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
|
/*###################################################################################
#
# Embperl - Copyright (c) 1997-2008 Gerald Richter / ecos gmbh www.ecos.de
# Embperl - Copyright (c) 2008-2014 Gerald Richter
#
# You may distribute under the terms of either the GNU General Public
# License or the Artistic License, as specified in the Perl README file.
# For use with Apache httpd and mod_perl, see also Apache copyright.
#
# THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
# WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# $Id: epinit.c 1578075 2014-03-16 14:01:14Z richter $
#
###################################################################################*/
#include "ep.h"
#include "epmacro.h"
#include "xs/ep_xs_typedefs.h"
#include "xs/ep_xs_sv_convert.h"
#include "epdefault.c"
SV ep_sv_undef ; /* we need our own undef value, because when
storing a PL_sv_undef with Perl 5.8.0 in a hash
Perl takes it as a placeholder and pretents it isn't there :-( */
#ifndef PERL_IMPLICIT_CONTEXT
SV * embperl_ThreadDataRV ;
#define SINGLETHREAD
#endif
#define OPTPREFIX EMBPERL_PACKAGE_STR
#define EMBPERL_APP_PACKAGE EMBPERL_PACKAGE_STR"::Application"
#define EMBPERL_REQ_PACKAGE EMBPERL_PACKAGE_STR"::Req"
#define EMBPERL_THREAD_PACKAGE EMBPERL_PACKAGE_STR"::Thread"
#define FDAT_NAME "fdat"
#define EMBPERL_FDAT_NAME EMBPERL_PACKAGE_STR"::"FDAT_NAME
#define EMBPERL_SPLIFDAT_NAME EMBPERL_PACKAGE_STR"::splitfdat"
#define FFLD_NAME "ffld"
#define EMBPERL_FFLD_NAME EMBPERL_PACKAGE_STR"::"FFLD_NAME
#define EMBPERL_HDR_NAME EMBPERL_PACKAGE_STR"::http_headers_out"
#define EMBPERL_IDAT_NAME EMBPERL_PACKAGE_STR"::idat"
#define PARAM_NAME "param"
#define EMBPERL_PARAM_NAME EMBPERL_PACKAGE_STR"::"PARAM_NAME
#define EMBPERL_REQ_NAME EMBPERL_PACKAGE_STR"::req"
#define EMBPERL_APP_NAME EMBPERL_PACKAGE_STR"::app"
#define EMBPERL_ENV_NAME "ENV"
#define EMBPERL_EscMode_NAME EMBPERL_PACKAGE_STR"::escmode"
#define EMBPERL_CurrNode_NAME EMBPERL_PACKAGE_STR"::_ep_node"
static int bInitDone = 0 ; /* c part is already initialized */
static int nRequestCount = 1 ;
static perl_mutex RequestCountMutex ;
static tMemPool * pMainPool ;
static tReq NullRequest ; /* a request object with all zero, to point for deleted objects */
/* -------------------------------------------------------------------------
*
* Options lists for configuration
*
*/
#define OPTION(a,b) { #a, a}, { #b, a},
tOptionEntry OptionsDEBUG[] =
{
OPTION(dbgStd, std)
OPTION(dbgMem,Mem)
OPTION(dbgEval,Eval)
OPTION(dbgCmd,Cmd)
OPTION(dbgEnv,Env)
OPTION(dbgForm,Form)
OPTION(dbgTab,Tab)
OPTION(dbgInput,Input)
OPTION(dbgFlushOutput,FlushOutput)
OPTION(dbgFlushLog,FlushLog)
OPTION(dbgAllCmds,AllCmds)
OPTION(dbgSource,Source)
OPTION(dbgFunc,Func)
OPTION(dbgLogLink,LogLink)
OPTION(dbgDefEval,DefEval)
OPTION(dbgOutput,Output)
OPTION(dbgDOM,DOM)
OPTION(dbgRun,Run)
OPTION(dbgHeadersIn,HeadersIn)
OPTION(dbgShowCleanup,ShowCleanup)
OPTION(dbgProfile,Profile)
OPTION(dbgSession,Session)
OPTION(dbgImport,Import)
OPTION(dbgBuildToken,BuildToken)
OPTION(dbgParse,Parse)
OPTION(dbgObjectSearch,ObjectSearch)
OPTION(dbgCache,Cache)
OPTION(dbgCompile,Compile)
OPTION(dbgXML,XML)
OPTION(dbgXSLT,XSLT)
OPTION(dbgCheckpoint,Checkpoint)
OPTION(dbgAll,All)
} ;
#define OPTION_OPT(a) OPTION(opt##a, a)
tOptionEntry OptionsOPTIONS[] =
{
OPTION_OPT(DisableVarCleanup)
OPTION_OPT(DisableEmbperlErrorPage)
OPTION_OPT(SafeNamespace)
OPTION_OPT(OpcodeMask)
OPTION_OPT(RawInput)
OPTION_OPT(SendHttpHeader)
OPTION_OPT(EarlyHttpHeader)
OPTION_OPT(DisableChdir)
OPTION_OPT(DisableFormData)
OPTION_OPT(DisableHtmlScan)
OPTION_OPT(DisableInputScan)
OPTION_OPT(DisableTableScan)
OPTION_OPT(DisableMetaScan)
OPTION_OPT(AllFormData)
OPTION_OPT(RedirectStdout)
OPTION_OPT(UndefToEmptyValue)
OPTION_OPT(NoHiddenEmptyValue)
OPTION_OPT(AllowZeroFilesize)
OPTION_OPT(ReturnError)
OPTION_OPT(KeepSrcInMemory)
OPTION_OPT(KeepSpaces)
OPTION_OPT(OpenLogEarly)
OPTION_OPT(NoUncloseWarn)
OPTION_OPT(DisableSelectScan)
OPTION_OPT(ShowBacktrace)
OPTION_OPT(EnableChdir)
OPTION_OPT(FormDataNoUtf8)
} ;
#define OPTION_ESC(a) OPTION(esc##a, a)
tOptionEntry OptionsESCMODE[] =
{
OPTION_ESC(None)
OPTION_ESC(Html)
OPTION_ESC(Url)
OPTION_ESC(Escape)
OPTION_ESC(XML)
OPTION_ESC(Std)
} ;
#define OPTION_IESC(a) OPTION(iesc##a, a)
tOptionEntry OptionsINPUT_ESCMODE[] =
{
OPTION_IESC(None)
OPTION_IESC(Html)
OPTION_IESC(Url)
OPTION_IESC(RemoveTags)
} ;
#define OPTION_OMODE(a) OPTION(omode##a, a)
tOptionEntry OptionsOUTPUT_MODE[] =
{
OPTION_OMODE(Html)
OPTION_OMODE(Xml)
} ;
#define OPTION_OCHARSET(a) OPTION(ocharset##a, a)
tOptionEntry OptionsOUTPUT_ESC_CHARSET[] =
{
OPTION_OCHARSET(Utf8)
OPTION_OCHARSET(Latin1)
OPTION_OCHARSET(Latin2)
} ;
#define OPTION_SMODE(a) OPTION(smode##a, a)
tOptionEntry OptionsSESSION_MODE[] =
{
OPTION_SMODE(None)
OPTION_SMODE(UDatCookie)
OPTION_SMODE(UDatParam)
OPTION_SMODE(UDatUrl)
OPTION_SMODE(SDatParam)
} ;
/*---------------------------------------------------------------------------
* embperl_SetupThread
*/
/*!
*
* \_en
* Setup an thread object. Either take an existing one, if this thread
* already has a azocitaed object or create a new one.
*
* \endif
*
* \_de
* Initialisiert ein Threadobjekt. Ist dem Thread schon ein Objekt zugeorndet
* wird das bestehende genutzt, ansonsten ein neues zur?ck geliefert.
* \endif
*
* ------------------------------------------------------------------------ */
int embperl_SetupThread (/*in*/ pTHX_
/*out*/tThreadData * * ppThread)
{
tThreadData * pThread ;
SV * * ppSV ;
#ifdef SINGLETHREAD
ppSV = &embperl_ThreadDataRV ;
#else
ppSV = hv_fetch (PL_modglobal, "Embperl::Thread", 15, 1) ;
#endif
if (!ppSV)
{
LogErrorParam (NULL, rcHashError, "PL_modglobal (key=Embperl::Thread)", "") ;
return rcHashError ;
}
if (!*ppSV || !SvOK(*ppSV))
{
SV * pThreadRV ;
SV * pThreadSV ;
HV * pStash = gv_stashpv (EMBPERL_PACKAGE_STR, 1) ;
tMemPool * pPool = ep_make_sub_pool (pMainPool) ;
epxs_Embperl__Thread_create_obj(pThread,pThreadSV,pThreadRV,ep_palloc(pPool,sizeof(*pThread))) ;
#ifdef PERL_IMPLICIT_CONTEXT
pThread -> pPerlTHX = aTHX ;
#endif
pThread -> pPool = pPool ;
pThread -> pMainPool = pMainPool ;
pThread -> nPid = getpid () ;
pThread -> pApplications = newHV () ;
pThread -> pFormHash = perl_get_hv (EMBPERL_FDAT_NAME, GV_ADD | GV_ADDMULTI) ;
SvREFCNT_inc(pThread -> pFormHash) ;
pThread -> pFormHashGV = *((GV **)hv_fetch (pStash, FDAT_NAME, sizeof (FDAT_NAME) - 1, 0)) ;
pThread -> pFormSplitHash = perl_get_hv (EMBPERL_SPLIFDAT_NAME, GV_ADD | GV_ADDMULTI) ;
SvREFCNT_inc(pThread -> pFormSplitHash) ;
pThread -> pFormArray = perl_get_av (EMBPERL_FFLD_NAME, GV_ADD | GV_ADDMULTI) ;
SvREFCNT_inc(pThread -> pFormArray) ;
pThread -> pFormArrayGV = *((GV **)hv_fetch (pStash, FFLD_NAME, sizeof (FFLD_NAME) - 1, 0)) ;
pThread -> pHeaderHash = perl_get_hv (EMBPERL_HDR_NAME, GV_ADD | GV_ADDMULTI) ;
SvREFCNT_inc(pThread -> pHeaderHash) ;
pThread -> pInputHash = perl_get_hv (EMBPERL_IDAT_NAME, GV_ADD | GV_ADDMULTI) ;
SvREFCNT_inc(pThread -> pInputHash) ;
#ifdef DMALLOC
pThread -> pEnvHash = Perl_get_hv(aTHX_ EMBPERL_ENV_NAME, GV_ADD | GV_ADDMULTI) ;
#else
pThread -> pEnvHash = perl_get_hv (EMBPERL_ENV_NAME, GV_ADD | GV_ADDMULTI) ;
#endif
SvREFCNT_inc(pThread -> pEnvHash) ;
pThread -> pParamArray = perl_get_av (EMBPERL_PARAM_NAME, GV_ADD | GV_ADDMULTI) ;
SvREFCNT_inc(pThread -> pParamArray) ;
pThread -> pParamArrayGV = *((GV **)hv_fetch (pStash, PARAM_NAME, sizeof (PARAM_NAME) - 1, 0)) ;
pThread -> pReqRV = perl_get_sv (EMBPERL_REQ_NAME, GV_ADD | GV_ADDMULTI) ;
SvREFCNT_inc(pThread -> pReqRV) ;
pThread -> pAppRV = perl_get_sv (EMBPERL_APP_NAME, GV_ADD | GV_ADDMULTI) ;
SvREFCNT_inc(pThread -> pAppRV) ;
*ppSV = pThreadRV ;
}
else
{
pThread = epxs_sv2_Embperl__Thread(*ppSV) ;
}
*ppThread = pThread ;
return ok ;
}
/*---------------------------------------------------------------------------
* embperl_GetThread
*/
/*!
*
* \_en
* Returns already has a azocitaed object thread object. The thread object
* must be setup before via embperl_SetupThread
* \endif
*
* \_de
* Liefert das diesem Thread zugeordnete Thread-Objekt zur?ck. Das Objekt mu?
* vorher mittels embperl_SetupThread initialisiert worden sein.
* \endif
*
* ------------------------------------------------------------------------ */
tThreadData * embperl_GetThread (/*in*/ pTHX)
{
tThreadData * pThread ;
int rc ;
if ((rc = embperl_SetupThread (aTHX_ &pThread)) != ok)
{
LogError (NULL, rc) ;
return NULL ;
}
return pThread ;
}
/*---------------------------------------------------------------------------
* embperl_EndPass1
*/
/*!
*
* \_en
* Call when configuration pass 1 of apache is done.
* \endif
*
* \_de
* Wird aufgerufen wenn Pass 1 des Einlesens der Konfiguration beendet ist.
* \endif
*
* ------------------------------------------------------------------------ */
int embperl_EndPass1 (void)
{
tThreadData * pThread ;
dTHX ;
pThread = embperl_GetThread (aTHX) ;
hv_clear (pThread -> pApplications) ;
return ok ;
}
/*---------------------------------------------------------------------------
* embperl_CreateSessionObject
*/
/*!
*
* \_en
* Creates a new session object.
*
* \endif
*
* \_de
* Erzeugt eine neues Sessionobjekt.
*
* \endif
*
* ------------------------------------------------------------------------ */
static int embperl_CreateSessionObject(/*in*/ tApp * a,
/*in*/ HV * pArgs,
/*out*/ HV * * ppHash,
/*out*/ SV * * ppObj)
{
epaTHX_
dSP ;
tAppConfig * pCfg = &a -> Config ;
char * sPackage = pCfg -> sSessionHandlerClass ;
HV * pHash = newHV () ;
SV * pTie = NULL ;
int n ;
SV * pSVCode ;
pSVCode = newSVpvf ("require %s", sPackage) ;
newSVpvf2(pSVCode) ;
/* there is no c api to the require function, eval it... */
perl_eval_sv(pSVCode, G_EVAL | G_DISCARD) ;
SvREFCNT_dec(pSVCode);
tainted = 0 ;
if (SvTRUE (ERRSV))
{
STRLEN l ;
if (strcmp (sPackage, "Apache::SessionX") != 0 ||
GetHashValueStr (aTHX_ a -> pThread -> pEnvHash, "GATEWAY_INTERFACE", NULL))
LogErrorParam (a, rcSetupSessionErr, SvPV (ERRSV, l), NULL) ;
sv_setpv(ERRSV,"");
return rcEvalErr ;
}
SPAGAIN;
PUSHMARK(sp);
XPUSHs(sv_2mortal(newSVpv(sPackage, 0)));
XPUSHs(&sv_undef); /* id */
XPUSHs(sv_2mortal (newRV((SV *)pArgs)));
PUTBACK;
n = perl_call_method ("TIEHASH", G_EVAL | G_SCALAR) ;
SPAGAIN;
if (n > 0)
pTie = POPs ;
PUTBACK;
if (SvTRUE (ERRSV))
{
STRLEN l ;
LogErrorParam (a, rcSetupSessionErr, SvPV (ERRSV, l), NULL) ;
sv_setpv(ERRSV,"");
return rcEvalErr ;
}
if (n == 0 || !SvROK(pTie))
{
LogErrorParam (a, rcSetupSessionErr, "TIEHASH didn't returns a hashref", sPackage) ;
return rcNotHashRef ;
}
hv_magic(pHash, (GV *)pTie, 'P') ;
*ppHash = pHash ;
*ppObj = SvREFCNT_inc(pTie) ;
return ok ;
}
/*---------------------------------------------------------------------------
* embperl_SetupSessionObjects
*/
/*!
*
* \_en
* Setup the session onbjects.
*
* \endif
*
* \_de
* Initialisiert neue Sessionobjekte.
*
* \endif
*
* ------------------------------------------------------------------------ */
int embperl_SetupSessionObjects (/*in*/ tApp * a)
{
epaTHX_
int rc ;
SV * pStore ;
SV ** ppStore ;
SV * pLocker ;
SV ** ppLocker ;
SV * pSerializer ;
SV ** ppSerializer ;
SV * pGenerator ;
SV ** ppGenerator ;
tAppConfig * pCfg = &a -> Config ;
HV * pArgs = pCfg -> pSessionArgs ;
HV * pArgs1 ;
HV * pArgs2 ;
HV * pArgs3 ;
dSP ;
if (strcmp (pCfg -> sSessionHandlerClass, "no") == 0)
return ok ;
if (!pArgs)
pCfg -> pSessionArgs = pArgs = newHV() ;
if (pCfg -> pSessionClasses)
{
if ((ppStore = av_fetch (pCfg -> pSessionClasses, 0, 0)))
pStore = SvREFCNT_inc(*ppStore) ;
else
pStore = newSVpv("File", 4) ;
hv_store (pArgs, "Store", 5, pStore, 0) ;
if ((ppLocker = av_fetch (pCfg -> pSessionClasses, 1, 0)))
pLocker = SvREFCNT_inc(*ppLocker) ;
else
pLocker = newSVpv("Null", 4) ;
hv_store (pArgs, "Lock", 4, pLocker, 0) ;
if ((ppSerializer = av_fetch (pCfg -> pSessionClasses, 2, 0)))
pSerializer = SvREFCNT_inc(*ppSerializer) ;
else
pSerializer = newSVpv("Storable", 8) ;
hv_store (pArgs, "Serialize", 9, pSerializer, 0) ;
if ((ppGenerator = av_fetch (pCfg -> pSessionClasses, 3, 0)))
pGenerator = SvREFCNT_inc(*ppGenerator) ;
else
pGenerator = newSVpv("MD5", 3) ;
hv_store (pArgs, "Generate", 8, pGenerator, 0) ;
}
else
{
/* workaround for perl bug in newHVhv when to less hash entries */
hv_store (pArgs, "__dummy1__", 10, newSViv (1), 0) ;
hv_store (pArgs, "__dummy2__", 10, newSViv (1), 0) ;
hv_store (pArgs, "__dummy3__", 10, newSViv (1), 0) ;
hv_store (pArgs, "__dummy4__", 10, newSViv (1), 0) ;
}
if (pCfg -> sSessionConfig)
hv_store (pArgs, "config", 5, newSVpv (pCfg -> sSessionConfig, 0), 0) ;
hv_store (pArgs, "lazy", 4, newSViv (1), 0) ;
hv_store (pArgs, "create_unknown", 14, newSViv (1), 0) ;
pArgs1 = newHVhv(pArgs) ;
hv_store (pArgs1, "Transaction", 11, newSViv (1), 0) ;
pArgs2 = newHVhv(pArgs) ;
hv_store (pArgs2, "recreate_id", 11, newSViv (1), 0) ;
pArgs3 = newHVhv(pArgs2) ;
if ((rc = embperl_CreateSessionObject (a, pArgs1, &a -> pAppHash, &a -> pAppObj)) != ok)
return rc ;
SPAGAIN ;
PUSHMARK(sp);
XPUSHs(a -> pAppObj);
XPUSHs(sv_2mortal (newSVpv(a -> Config.sAppName, 0)));
PUTBACK;
perl_call_method ("setidfrom", G_DISCARD) ;
if ((rc = embperl_CreateSessionObject (a, pArgs2, &a -> pUserHash, &a -> pUserObj)) != ok)
return rc ;
hv_store (pArgs3, "newid", 5, newSViv (1), 0) ;
if ((rc = embperl_CreateSessionObject (a, pArgs3, &a -> pStateHash, &a -> pStateObj)) != ok)
return rc ;
return ok ;
}
/*---------------------------------------------------------------------------
* embperl_SetupApp
*/
/*!
*
* \_en
* Setup an application object. Either take an existing one, if the
* application is already created for that thread or create a new
* one.
*
* @param pThread per thread data
* @param pApacheCfg apache configuration vector
* @param pPerlParam parameters passed from Perl
* \endif
*
* \_de
* Initialisiert ein Applicationobjekt. Entweder wird ein bereits bestehendes
* benutzt, oder falls nicht vorhanden, ein neues erzeugt.
*
* @param pThread per thread daten
* @param pApacheCfg apache Konfigurations Vector
* @param pPerlParam Parameter die von Perl aus ?bergeben wurden
* \endif
*
* ------------------------------------------------------------------------ */
int embperl_SetupApp (/*in*/ pTHX_
/*in*/ tThreadData * pThread,
/*in*/ tApacheDirConfig * pApacheCfg,
/*in*/ SV * pPerlParam,
/*out*/tApp * * ppApp)
{
char * sAppName = NULL ;
tApp * pApp = NULL ;
HV * pParam = NULL ;
if (pPerlParam && SvROK(pPerlParam))
{
pParam = (HV *)SvRV(pPerlParam) ;
sAppName = GetHashValueStr (aTHX_ pParam, "app_name", NULL) ;
if (!sAppName) // backward compability to broken appname
sAppName = GetHashValueStr (aTHX_ pParam, "appname", NULL) ;
}
if (!sAppName)
{
#ifdef APACHE
if (pApacheCfg)
sAppName = embperl_GetApacheAppName (pApacheCfg) ;
else
#endif
sAppName = embperl_GetCGIAppName (pThread) ;
}
if (sAppName)
pApp = (tApp * )GetHashValuePtr (NULL, pThread -> pApplications, sAppName, NULL) ;
if (!pApp)
{
int rc ;
SV * pAppSV ;
SV * pAppRV ;
SV * pSV ;
SV * pRV ;
tAppConfig * pCfg ;
tMemPool * pPool = ep_make_sub_pool (pThread -> pPool) ;
epxs_Embperl__App_create_obj(pApp,pAppSV,pAppRV,ep_palloc(pPool,sizeof(*pApp))) ;
epxs_Embperl__App__Config_create_obj(pCfg,pSV,pRV,&pApp -> Config) ;
#ifdef PERL_IMPLICIT_CONTEXT
pApp -> pPerlTHX = aTHX ;
#endif
pApp -> pPool = pPool ;
pCfg -> pPool = pPool ;
#ifdef APACHE
if (pApacheCfg)
embperl_GetApacheAppConfig (pThread, pPool, pApacheCfg, &pApp -> Config) ;
else
#endif
{
bool bUseEnv = 0 ;
bool bUseRedirectEnv = 0 ;
if (pParam)
{
bUseEnv = (bool)GetHashValueInt (aTHX_ pParam, "use_env", 0) ;
bUseRedirectEnv = (bool)GetHashValueInt (aTHX_ pParam, "use_redirect_env", 0) ;
}
embperl_GetCGIAppConfig (pThread, pPool, &pApp -> Config, bUseEnv, bUseRedirectEnv, 1) ;
}
SetHashValueInt (NULL, pThread -> pApplications, sAppName, (IV)pApp) ;
pApp -> pThread = pThread ;
if (pParam)
Embperl__App__Config_new_init(aTHX_ &pApp -> Config, (SV *)pParam, 0) ;
tainted = 0 ;
if (pApp -> Config.sLog && pApp -> Config.sLog[0])
{
if ((rc = OpenLog (pApp)) != ok)
{
pApp -> Config.bDebug = 0 ; /* Turn debbuging off, only errors will go to stderr */
LogErrorParam (pApp, rc, pApp -> Config.sLog, Strerror(errno)) ;
}
}
if (pApp -> Config.sAppHandlerClass)
{
HV * stash = gv_stashpv(pApp -> Config.sAppHandlerClass, TRUE) ;
sv_bless(pApp -> _perlsv, stash) ;
}
embperl_SetupSessionObjects (pApp) ;
}
sv_setsv(pThread -> pAppRV, pApp -> _perlsv) ;
*ppApp = pApp ;
return ok ;
}
static int notused ;
#if 0
INTMG (TabCount, pCurrReq -> TableStack.State.nCount, pCurrReq -> TableStack.State.nCountUsed, ;)
INTMG (TabRow, pCurrReq -> TableStack.State.nRow, pCurrReq -> TableStack.State.nRowUsed, ;)
INTMG (TabCol, pCurrReq -> TableStack.State.nCol, pCurrReq -> TableStack.State.nColUsed, ;)
INTMG (TabMaxRow, pCurrReq -> nTabMaxRow, notused, ;)
INTMG (TabMaxCol, pCurrReq -> nTabMaxCol, notused, ;)
INTMG (TabMode, pCurrReq -> nTabMode, notused, ;)
#endif
INTMG_COMP (EscMode, Config.nEscMode, notused, NewEscMode (CurrReq, pSV))
#ifdef EP2
INTMGshort_COMP (CurrNode, xCurrNode)
#endif
OPTMGRD_COMP (optDisableVarCleanup , Config.bOptions)
OPTMG_COMP (optDisableEmbperlErrorPage, Config.bOptions)
OPTMG_COMP (optReturnError , Config.bOptions)
OPTMGRD_COMP (optSafeNamespace , Config.bOptions)
OPTMGRD_COMP (optOpcodeMask , Config.bOptions)
OPTMG_COMP (optRawInput , Config.bOptions)
OPTMG_COMP (optSendHttpHeader , Config.bOptions)
OPTMGRD_COMP (optDisableChdir , Config.bOptions)
OPTMG_COMP (optDisableHtmlScan , Config.bOptions)
OPTMGRD_COMP (optEarlyHttpHeader , Config.bOptions)
OPTMGRD_COMP (optDisableFormData , Config.bOptions)
OPTMG_COMP (optDisableInputScan , Config.bOptions)
OPTMG_COMP (optDisableTableScan , Config.bOptions)
OPTMG_COMP (optDisableMetaScan , Config.bOptions)
OPTMGRD_COMP (optAllFormData , Config.bOptions)
OPTMGRD_COMP (optRedirectStdout , Config.bOptions)
OPTMG_COMP (optUndefToEmptyValue , Config.bOptions)
OPTMG_COMP (optNoHiddenEmptyValue , Config.bOptions)
OPTMGRD_COMP (optAllowZeroFilesize , Config.bOptions)
OPTMGRD_COMP (optKeepSrcInMemory , Config.bOptions)
OPTMG_COMP (optKeepSpaces , Config.bOptions)
OPTMG_COMP (optOpenLogEarly , Config.bOptions)
OPTMG_COMP (optNoUncloseWarn , Config.bOptions)
OPTMG_COMP (dbgStd , Config.bDebug)
OPTMG_COMP (dbgMem , Config.bDebug)
OPTMG_COMP (dbgEval , Config.bDebug)
OPTMG_COMP (dbgCmd , Config.bDebug)
OPTMG_COMP (dbgEnv , Config.bDebug)
OPTMG_COMP (dbgForm , Config.bDebug)
OPTMG_COMP (dbgTab , Config.bDebug)
OPTMG_COMP (dbgInput , Config.bDebug)
OPTMG_COMP (dbgFlushOutput , Config.bDebug)
OPTMG_COMP (dbgFlushLog , Config.bDebug)
OPTMG_COMP (dbgAllCmds , Config.bDebug)
OPTMG_COMP (dbgSource , Config.bDebug)
OPTMG_COMP (dbgFunc , Config.bDebug)
OPTMG_COMP (dbgLogLink , Config.bDebug)
OPTMG_COMP (dbgDefEval , Config.bDebug)
OPTMG_COMP (dbgHeadersIn , Config.bDebug)
OPTMG_COMP (dbgShowCleanup , Config.bDebug)
OPTMG_COMP (dbgProfile , Config.bDebug)
OPTMG_COMP (dbgSession , Config.bDebug)
OPTMG_COMP (dbgImport , Config.bDebug)
/* ---------------------------------------------------------------------------- */
/* add magic to integer var */
/* */
/* in sVarName = Name of varibale */
/* in pVirtTab = pointer to virtual table */
/* */
/* ---------------------------------------------------------------------------- */
static int AddMagic (/*i/o*/ tApp * a,
/*in*/ char * sVarName,
/*in*/ MGVTBL * pVirtTab)
{
SV * pSV ;
struct magic * pMagic ;
epaTHX ;
EPENTRY (AddMagic) ;
pSV = perl_get_sv (sVarName, TRUE) ;
sv_magic (pSV, NULL, 0, sVarName, strlen (sVarName)) ;
sv_setiv (pSV, 0) ;
pMagic = mg_find (pSV, 0) ;
if (pMagic)
pMagic -> mg_virtual = pVirtTab ;
else
{
LogError (NULL, rcMagicError) ;
return 1 ;
}
perl_get_sv (sVarName, TRUE) ; /* avoid warning */
return ok ;
}
/* ---------------------------------------------------------------------------- */
/* add magic to array */
/* */
/* in sVarName = Name of varibale */
/* in pVirtTab = pointer to virtual table */
/* */
/* ---------------------------------------------------------------------------- */
int AddMagicAV (/*i/o*/ register req * r,
/*in*/ char * sVarName,
/*in*/ MGVTBL * pVirtTab)
{
SV * pSV ;
struct magic * pMagic ;
epTHX ;
EPENTRY (AddMagicAV) ;
pSV = (SV *)perl_get_av (sVarName, TRUE) ;
sv_magic (pSV, NULL, 'P', sVarName, strlen (sVarName)) ;
pMagic = mg_find (pSV, 0) ;
if (pMagic)
pMagic -> mg_virtual = pVirtTab ;
else
{
LogError (r, rcMagicError) ;
return 1 ;
}
return ok ;
}
/* ---------------------------------------------------------------------------- */
/* init embperl module */
/* */
/* in nIOType = type of requested i/o */
/* */
/* ---------------------------------------------------------------------------- */
int embperl_Init (/*in*/ pTHX_
/*in*/ SV * pApacheSrvSV,
/*in*/ SV * pPerlParam,
/*in*/ server_rec * ap_s)
{
int rc ;
tThreadData * pThread ;
tApp * pApp ;
tApacheDirConfig * pApacheCfg = NULL ;
memcpy (&ep_sv_undef, &PL_sv_undef, sizeof (PL_sv_undef)) ;
#ifdef APACHE
if (pApacheSrvSV && SvROK (pApacheSrvSV))
{
/* when running under mod_perl only register the module */
/* rest will be call from module initialzation when config has been read */
ap_s = epxs_sv2_Apache__Server(pApacheSrvSV) ;
embperl_ApacheAddModule () ;
#ifdef APACHE2
#else
return ok ;
#endif
}
#endif
if (!pMainPool)
pMainPool = ep_init_alloc() ;
if ((rc = embperl_SetupThread (aTHX_ &pThread)) != ok)
return rc ;
#ifdef APACHE
if (ap_s)
{
embperl_GetApacheConfig (pThread, NULL, ap_s, &pApacheCfg) ;
}
#endif
if ((rc = embperl_SetupApp (aTHX_ pThread, pApacheCfg, pPerlParam, &pApp)) != ok)
return rc ;
ADDINTMG (EscMode)
ADDINTMG (CurrNode)
ADDOPTMG (optDisableVarCleanup )
ADDOPTMG (optDisableEmbperlErrorPage)
ADDOPTMG (optReturnError)
ADDOPTMG (optSafeNamespace )
ADDOPTMG (optOpcodeMask )
ADDOPTMG (optRawInput )
ADDOPTMG (optSendHttpHeader )
ADDOPTMG (optDisableChdir )
ADDOPTMG (optDisableHtmlScan )
ADDOPTMG (optEarlyHttpHeader )
ADDOPTMG (optDisableFormData )
ADDOPTMG (optDisableInputScan )
ADDOPTMG (optDisableTableScan )
ADDOPTMG (optDisableMetaScan )
ADDOPTMG (optAllFormData )
ADDOPTMG (optRedirectStdout )
ADDOPTMG (optUndefToEmptyValue )
ADDOPTMG (optNoHiddenEmptyValue )
ADDOPTMG (optAllowZeroFilesize )
ADDOPTMG (optKeepSrcInMemory )
ADDOPTMG (optKeepSpaces )
ADDOPTMG (optOpenLogEarly )
ADDOPTMG (optNoUncloseWarn )
ADDOPTMG (dbgStd )
ADDOPTMG (dbgMem )
ADDOPTMG (dbgEval )
ADDOPTMG (dbgCmd )
ADDOPTMG (dbgEnv )
ADDOPTMG (dbgForm )
ADDOPTMG (dbgTab )
ADDOPTMG (dbgInput )
ADDOPTMG (dbgFlushOutput )
ADDOPTMG (dbgFlushLog )
ADDOPTMG (dbgAllCmds )
ADDOPTMG (dbgSource )
ADDOPTMG (dbgFunc )
ADDOPTMG (dbgLogLink )
ADDOPTMG (dbgDefEval )
ADDOPTMG (dbgHeadersIn )
ADDOPTMG (dbgShowCleanup )
ADDOPTMG (dbgProfile )
ADDOPTMG (dbgSession )
ADDOPTMG (dbgImport )
if (bInitDone)
return ok ; /* the rest needs to be done only once per process */
#if defined (_MDEBUG) && defined (WIN32)
_CrtSetReportHook( EmbperlCRTDebugOutput );
#endif
DomInit (pApp) ;
Cache_Init (pApp) ;
Provider_Init (pApp) ;
#ifdef APACHE2
ApFilter_Init (pApp) ;
#endif
#ifdef XALAN
embperl_Xalan_Init () ;
#endif
#ifdef LIBXSLT
embperl_LibXSLT_Init () ;
#endif
ep_create_mutex(RequestCountMutex) ;
bInitDone = 1 ;
#ifdef APACHE
{
int preload = 1 ;
if (ap_s)
{
module * m ;
if ((m = ap_find_linked_module("mod_perl.c")))
{
if (m -> dynamic_load_handle)
preload = 0 ;
}
}
if (preload)
{
dSP;
PUSHMARK(sp) ;
perl_call_pv ("Embperl::PreLoadFiles", G_DISCARD) ;
}
}
#else
{
dSP;
PUSHMARK(sp) ;
perl_call_pv ("Embperl::PreLoadFiles", G_DISCARD) ;
}
#endif
return rc ;
}
/*---------------------------------------------------------------------------
* embperl_GetFormData
*/
/*!
*
* \_en
* Takes the given form data and put them in %fdat/@ffld
* \endif
*
* \_de
* Nimmt die ?bergebenen Formulardaten und legt sie in %fdat/@ffld ab
* \endif
*
* ------------------------------------------------------------------------ */
static int embperl_GetFormData (/*i/o*/ register req * r,
/*in*/ char * pQueryString,
/*in*/ int nLen)
{
int num ;
char * p ;
char * pMem ;
int nVal ;
int nKey ;
char * pKey ;
char * pVal ;
SV * pSVV ;
SV * pSVK ;
SV * * ppSV ;
AV * pFormArray = r -> pThread -> pFormArray ;
HV * pFormHash = r -> pThread -> pFormHash ;
bool bAll = (r -> Config.bOptions & optAllFormData) != 0 ;
bool bNoUtf8 = (r -> Config.bOptions & optFormDataNoUtf8) != 0 ;
bool bDebug = (r -> Config.bDebug & dbgForm) != 0 ;
int mayutf8 = 0 ;
bool bInValue = 0 ;
char c ;
epTHX ;
if (nLen == 0)
return ok ;
if ((pMem = _malloc (r, nLen + 4)) == NULL)
return rcOutOfMemory ;
p = pMem ;
nKey = nVal = 0 ;
pKey = pVal = p ;
while (1)
{
switch (nLen > 0?*pQueryString:'\0')
{
case '+':
pQueryString++ ;
nLen-- ;
*p++ = ' ' ;
break ;
case '%':
pQueryString++ ;
nLen-- ;
num = 0 ;
if (*pQueryString)
{
if (toupper (*pQueryString) >= 'A')
num += (toupper (*pQueryString) - 'A' + 10) << 4 ;
else
num += ((*pQueryString) - '0') << 4 ;
pQueryString++ ;
}
if (*pQueryString)
{
if (toupper (*pQueryString) >= 'A')
num += (toupper (*pQueryString) - 'A' + 10) ;
else
num += ((*pQueryString) - '0') ;
pQueryString++ ;
nLen-- ;
}
*p++ = num ;
break ;
case ';':
case '&':
bInValue = 0 ;
pQueryString++ ;
nLen-- ;
case '\0':
nVal = p - pVal ;
*p++ = '\0' ;
if (nKey > 0 && (nVal > 0 || (bAll)))
{
char * sid = NULL ;
sid = r -> pApp -> Config.sCookieName ;
if (sid)
{ /* remove session id */
if (strncmp (pKey, sid, nKey) != 0)
sid = NULL ;
else
{
char * p = strchr(pVal, ':') ;
if (p && *p)
{
char * p2 = strchr(p+1, ':') ;
if (p2)
*p2 = '\0' ;
r -> sSessionUserID = ep_pstrdup (r -> pPool, p + 1) ;
*p = '\0' ;
}
if (*pVal)
r -> sSessionStateID = ep_pstrdup (r -> pPool, pVal) ;
}
}
if (sid == NULL)
{ /* field is not the session id */
if (pVal > pKey)
pVal[-1] = '\0' ;
if ((ppSV = hv_fetch (pFormHash, pKey, nKey, 0)))
{ /* Field exists already -> append separator and field value */
sv_catpvn (*ppSV, &r -> Config.cMultFieldSep , 1) ;
sv_catpvn (*ppSV, pVal, nVal) ;
}
else
{ /* New Field -> store it */
pSVV = newSVpv (pVal, nVal) ;
#ifdef UTF8_IS_START
if (mayutf8 && is_utf8_string((U8*)pVal, nVal))
SvUTF8_on (pSVV) ;
#endif
if (hv_store (pFormHash, pKey, nKey, pSVV, 0) == NULL)
{
_free (r, pMem) ;
strcpy (r -> errdat1, "fdat") ;
return rcHashError ;
}
pSVK = newSVpv (pKey, nKey) ;
av_push (pFormArray, pSVK) ;
}
if (bDebug)
lprintf (r -> pApp, "[%d]FORM: %s=%s\n", r -> pThread -> nPid, pKey, pVal) ;
}
}
pKey = pVal = p ;
nKey = nVal = 0 ;
mayutf8 = 0 ;
if (*pQueryString == '\0')
{
_free (r, pMem) ;
return ok ;
}
break ;
case '=':
if (!bInValue)
{
nKey = p - pKey ;
*p++ = r -> Config.cMultFieldSep ;
nVal = 0 ;
pVal = p ;
pQueryString++ ;
nLen-- ;
bInValue = 1 ;
break ;
}
/* fall through */
default:
c = *p++ = *pQueryString++ ;
nLen-- ;
#ifdef UTF8_IS_START
if (!bNoUtf8)
mayutf8 += UTF8_IS_START(c) ;
#endif
break ;
}
}
return ok ;
}
/*---------------------------------------------------------------------------
* embperl_SetupFormData
*/
/*!
*
* \_en
* Get the posted form data and put them in %fdat/@ffld
* \endif
*
* \_de
* Lie?t die formular daten ein und legt sie in %fdat/@ffld ab
* \endif
*
* ------------------------------------------------------------------------ */
static int embperl_SetupFormData (/*i/o*/ register req * r)
{
epTHX_
char * p = NULL ;
char * f ;
int rc = ok ;
STRLEN len = 0 ;
char sLen [20] ;
const char * sType ;
hv_clear (r -> pThread -> pFormHash) ;
hv_clear (r -> pThread -> pFormSplitHash) ;
av_clear (r -> pThread -> pFormArray) ;
hv_clear (r -> pThread -> pInputHash) ;
if (r -> Config.bOptions & optDisableFormData)
return ok ;
/* print out of env set tainted, so reset it now */
tainted = 0 ;
#ifdef APACHE
if (r -> pApacheReq)
{
const char * sLength = apr_table_get(r -> pApacheReq->headers_in, "Content-Length") ;
sType = apr_table_get(r -> pApacheReq->headers_in, "Content-Type") ;
len = sLength?atoi (sLength):0 ;
}
else
#endif
{
sLen [0] = '\0' ;
GetHashValue (r, r -> pThread -> pEnvHash, "CONTENT_LENGTH", sizeof (sLen) - 1, sLen) ;
sType = GetHashValueStr (aTHX_ r -> pThread -> pEnvHash, "CONTENT_TYPE", "") ;
len = atoi (sLen) ;
}
if (sType && strncmp (sType, "multipart/form-data", 19) == 0)
{
dSP ;
PUSHMARK(sp);
XPUSHs(r -> _perlsv);
PUTBACK;
perl_call_method ("get_multipart_formdata", G_EVAL) ;
if (SvTRUE (ERRSV))
{
STRLEN l ;
strncpy (r -> errdat1, SvPV (ERRSV, l), sizeof (r -> errdat1) - 1) ;
LogError (r, rcEvalErr) ;
sv_setpv(ERRSV,"");
POPs ; /* cleanup stack */
}
tainted = 0 ;
return ok ;
}
if (len == 0)
{
p = r -> Param.sQueryInfo ;
len = p?strlen (p):0 ;
f = NULL ;
}
else
{
if ((p = _malloc (r, len + 1)) == NULL)
return rcOutOfMemory ;
if ((rc = OpenInput (r, NULL)) != ok)
{
_free (r, p) ;
return rc ;
}
iread (r, p, len) ;
CloseInput (r) ;
p[len] = '\0' ;
f = p ;
}
if (r -> Config.bDebug & dbgForm)
lprintf (r -> pApp, "[%d]Formdata... length = %d\n", r -> pThread -> nPid, len) ;
rc = embperl_GetFormData (r, p, len) ;
if (len > 0 && f)
{
r -> Param.sQueryInfo = f ;
f[len] = '\0' ;
}
return rc ;
}
/*---------------------------------------------------------------------------
* embperl_LogStartReq
*/
/*!
*
* \_en
* Log request startup, headers and environment
* \endif
*
* \_de
* Logged den Requeststart, HTTP-Header und Umgebungsvariablen
* \endif
*
* ------------------------------------------------------------------------ */
static void embperl_LogStartReq (/*i/o*/ req * r)
{
epTHX ;
if (r -> Config.bDebug)
{
time_t t = time(NULL) ;
lprintf (r -> pApp, "[%d]REQ: ***** Start Request at %s", r -> pThread -> nPid, ctime (&t)) ;
lprintf (r -> pApp, "[%d]Use App: %s\n", r -> pApp -> pThread -> nPid, r -> pApp -> Config.sAppName) ;
}
#ifdef APACHE
if (r -> pApacheReq && (r -> Config.bDebug & dbgHeadersIn))
{
int i;
const apr_array_header_t *hdrs_arr;
apr_table_entry_t *hdrs;
hdrs_arr = apr_table_elts (r -> pApacheReq->headers_in);
hdrs = (apr_table_entry_t *)hdrs_arr->elts;
lprintf (r -> pApp, "[%d]HDR: %d\n", r -> pThread -> nPid, hdrs_arr->nelts) ;
for (i = 0; i < hdrs_arr->nelts; ++i)
if (hdrs[i].key)
lprintf (r -> pApp, "[%d]HDR: %s=%s\n", r -> pThread -> nPid, hdrs[i].key, hdrs[i].val) ;
}
#endif
if (r -> Config.bDebug & dbgEnv)
{
SV * psv ;
HE * pEntry ;
char * pKey ;
I32 l ;
int savewarn = dowarn ;
dowarn = 0 ; /* no warnings here */
hv_iterinit (r -> pThread -> pEnvHash) ;
while ((pEntry = hv_iternext (r -> pThread -> pEnvHash)))
{
pKey = hv_iterkey (pEntry, &l) ;
psv = hv_iterval (r -> pThread -> pEnvHash, pEntry) ;
lprintf (r -> pApp, "[%d]ENV: %s=%s\n", r -> pThread -> nPid, pKey, SvPV (psv, na)) ;
}
dowarn = savewarn ;
}
}
/*---------------------------------------------------------------------------
* embperl_SetupRequest
*/
/*!
*
* \_en
* setup data for (http-)request object
* \endif
*
* \_de
* Initialisiert das Requestobjekt
* \endif
*
* ------------------------------------------------------------------------ */
int embperl_SetupRequest (/*in*/ pTHX_
/*in*/ SV * pApacheReqSV,
/*in*/ tApp * pApp,
/*in*/ tApacheDirConfig * pApacheCfg,
/*in*/ SV * pPerlParam,
/*out*/tReq * * ppReq)
{
tReq * r ;
tThreadData * pThread ;
SV * pReqSV ;
SV * pReqRV ;
SV * pSV ;
SV * pRV ;
tReqConfig * pConfig ;
tReqParam * pParam ;
char * pCookieName ;
HV * pParamHV = NULL ;
dSP ;
#ifdef APACHE
request_rec * pApacheReq ;
#endif
tMemPool * pPool = ep_make_sub_pool (pApp -> pPool) ;
tainted = 0 ;
if (pPerlParam && SvROK(pPerlParam))
pParamHV = (HV *)SvRV(pPerlParam) ;
epxs_Embperl__Req_create_obj(r,pReqSV,pReqRV,ep_palloc(pPool,sizeof(*r))) ;
epxs_Embperl__Req__Config_create_obj(pConfig,pSV,pRV,&r->Config) ;
epxs_Embperl__Req__Param_create_obj(pParam,pSV,pRV,&r->Param) ;
#ifdef PERL_IMPLICIT_CONTEXT
r -> pPerlTHX = aTHX ;
#endif
r -> pPool = pPool ;
pConfig -> pPool = pPool ;
pParam -> pPool = pPool ;
r -> pApp = pApp ;
pThread = r -> pThread = pApp -> pThread ;
r -> pPrevReq = pThread -> pCurrReq ;
pThread -> pCurrReq = r ;
pApp -> pCurrReq = r ;
sv_setsv(pThread -> pReqRV, r -> _perlsv) ;
r -> startclock = clock () ;
r -> stsv_count = sv_count ;
#ifdef PERL_IMPLICIT_CONTEXT
r -> pPerlTHX = aTHX ;
#endif
#ifdef APACHE
if (SvROK (pApacheReqSV))
pApacheReq = r -> pApacheReq = (request_rec *)SvIV((SV*)SvRV(pApacheReqSV));
else
pApacheReq = r -> pApacheReq = NULL ;
r -> pApacheReqSV = SvREFCNT_inc(pApacheReqSV) ;
if (pApacheReq)
{
embperl_GetApacheReqConfig (pApp, pPool, pApacheCfg, &r -> Config) ;
embperl_GetApacheReqParam (pApp, pPool, pApacheReq, &r -> Param) ;
}
else
#endif
{
bool bUseEnv = 0 ;
bool bUseRedirectEnv = 0 ;
if (pParamHV)
{
bUseEnv = (bool)GetHashValueInt (aTHX_ pParamHV, "use_env", 0) ;
bUseRedirectEnv = (bool)GetHashValueInt (aTHX_ pParamHV, "use_redirect_env", 0) ;
}
embperl_GetCGIReqConfig (pApp, pPool, &r -> Config, bUseEnv, bUseRedirectEnv, 1) ;
embperl_GetCGIReqParam (pApp, pPool, &r -> Param) ;
}
if (pParamHV)
{
char * fn = GetHashValueStrDup(aTHX_ pPool, pParamHV, "inputfile", NULL) ;
Embperl__Req__Config_new_init(aTHX_ &r -> Config, (SV *)pParamHV, 0) ;
Embperl__Req__Param_new_init(aTHX_ &r -> Param, (SV *)pParamHV, 0) ;
if (fn)
r -> Param.sFilename = fn ;
}
tainted = 0 ;
/*if (r -> Config.bDebug)
lprintf (r -> pApp, "[%d]ep_acquire_mutex(RequestCountMutex)\n", r -> pThread -> nPid) ; */
ep_acquire_mutex(RequestCountMutex) ;
r -> nRequestCount = nRequestCount++ ;
ep_release_mutex(RequestCountMutex) ;
/*if (r -> Config.bDebug)
lprintf (r -> pApp, "[%d]ep_release_mutex(RequestCountMutex)\n", r -> pThread -> nPid) ; */
r -> nRequestTime = time(NULL) ;
r -> pErrArray = newAV () ;
r -> pDomTreeAV = newAV () ;
r -> pCleanupAV = newAV () ;
r -> pCleanupPackagesHV = newHV () ;
r -> pMessages = newAV () ;
r -> pDefaultMessages = newAV () ;
pCookieName = r -> pApp -> Config.sCookieName ;
if (pCookieName)
{ /* remove session id */
char * pVal = GetHashValueStr (aTHX_ r -> Param.pCookies, pCookieName, NULL) ;
if (pVal)
r -> sSessionUserID = ep_pstrdup (r -> pPool, pVal) ;
}
if (r -> pApp -> Config.sCookieExpires)
{
char buf[256] ;
if (!embperl_CalcExpires(r -> pApp -> Config.sCookieExpires, buf, 0))
LogErrorParam (r -> pApp, rcTimeFormatErr, "EMBPERL_COOKIE_EXPIRES", r -> pApp -> Config.sCookieExpires) ;
else
r -> sCookieExpires = ep_pstrdup (r -> pPool, buf) ;
}
if (r -> pApp -> pUserHash)
r -> nSessionMgnt = 1 ;
r -> nLogFileStartPos = GetLogFilePos (pApp) ;
hv_clear (pThread -> pHeaderHash) ;
embperl_LogStartReq (r) ;
embperl_SetupFormData (r) ;
if (r -> sSessionUserID && pApp -> pUserObj)
{
tainted = 0 ;
SPAGAIN;
PUSHMARK(sp);
XPUSHs(pApp -> pUserObj);
XPUSHs(sv_2mortal(newSVpv(r -> sSessionUserID, 0)));
PUTBACK;
perl_call_method ("setid", 0) ;
}
if (r -> sSessionStateID && pApp -> pStateObj)
{
tainted = 0 ;
SPAGAIN;
PUSHMARK(sp);
XPUSHs(pApp -> pStateObj);
XPUSHs(sv_2mortal(newSVpv(r -> sSessionStateID, 0)));
PUTBACK;
perl_call_method ("setid", 0) ;
}
r -> sInitialCWD = ep_palloc(pPool, PATH_MAX * 2) ;
getcwd (r -> sInitialCWD, PATH_MAX * 2 - 1) ;
*ppReq = r ;
if (pApp -> Config.sAppHandlerClass)
{
tainted = 0 ;
SPAGAIN ;
PUSHMARK(sp);
XPUSHs(pApp -> _perlsv);
XPUSHs(r -> _perlsv);
PUTBACK;
perl_call_method ("init", G_EVAL) ;
tainted = 0 ;
if (SvTRUE (ERRSV))
{
STRLEN l ;
POPs ; /* cleanup stack */
LogErrorParam (pApp, rcEvalErr, SvPV (ERRSV, l), " while calling APP_HANDLER_CLASS -> init") ;
sv_setpv(ERRSV,"");
return rcEvalErr ;
}
}
tainted = 0 ;
return ok ;
}
/*---------------------------------------------------------------------------
* embperl_CleanupOutput
*/
/*!
*
* \_en
* cleanup data for component output object
* \endif
*
* \_de
* R?umt das Component-Ausgabe Objekt auf
* \endif
*
* ------------------------------------------------------------------------ */
int embperl_CleanupOutput (/*in*/ tReq * r,
/*in*/ tComponent * c)
{
epTHX_
tComponentOutput * pOutput = c -> pOutput ;
if (!pOutput || (c -> pPrev && c -> pPrev -> pOutput == pOutput))
{ /* this component uses the main output object */
return ok ;
}
CloseOutput (r, pOutput) ;
if (SvREFCNT(SvRV(pOutput -> _perlsv)) != 1)
{
char buf[20] ;
sprintf (buf, "%d", (int)SvREFCNT(SvRV(pOutput -> _perlsv)) - 1) ;
LogErrorParam (r -> pApp, rcRefcntNotOne, buf, "request.component.output") ;
}
sv_unmagic(SvRV(pOutput -> _perlsv), '~') ;
SvREFCNT_dec (pOutput -> _perlsv) ;
ep_destroy_pool (pOutput -> pPool) ;
return ok ;
}
/*---------------------------------------------------------------------------
* embperl_CleanupComponent
*/
/*!
*
* \_en
* cleanup component object
* \endif
*
* \_de
* Component-Objekt aufr?umen
* \endif
*
* ------------------------------------------------------------------------ */
int embperl_CleanupComponent (/*in*/ tComponent * c)
{
tReq * r = c -> pReq ;
epTHX_
SV * pHV ;
MAGIC * mg;
if (c -> Param.sISA && c -> sCurrPackage)
{
STRLEN l ;
SV * pName = newSVpvf ("%s::ISA", c -> sImportPackage) ;
AV * pCallerISA = perl_get_av (SvPV(pName, l), TRUE) ;
int i ;
int n = av_len(pCallerISA) + 1;
SV ** ppSV ;
newSVpvf2(pName) ;
SvREFCNT_dec (pName) ;
for (i = 0; i < n; i++)
{
if ((ppSV = av_fetch(pCallerISA, i, 0)) && *ppSV && strcmp (SvPV(*ppSV, l), c -> sCurrPackage) == 0)
break ;
}
if (n == i)
av_push(pCallerISA, newSVpv (c -> sCurrPackage, 0)) ;
}
embperl_CleanupOutput (r, c) ;
if (SvREFCNT(SvRV(c -> Config._perlsv)) != 1)
{
char buf[20] ;
sprintf (buf, "%d", (int)SvREFCNT(SvRV(c -> Config._perlsv)) - 1) ;
LogErrorParam (r -> pApp, rcRefcntNotOne, buf, "request.component.config") ;
}
if (SvREFCNT(SvRV(c -> Param._perlsv)) != 1)
{
char buf[20] ;
sprintf (buf, "%d", (int)SvREFCNT(SvRV(c -> Param._perlsv)) - 1) ;
LogErrorParam (r -> pApp, rcRefcntNotOne, buf, "request.component.param") ;
}
if (SvREFCNT(c -> _perlsv) != 1)
{
char buf[20] ;
sprintf (buf, "%d", (int)SvREFCNT(SvRV(c -> _perlsv)) - 1) ;
LogErrorParam (r -> pApp, rcRefcntNotOne, buf, "request.component") ;
}
Embperl__Component__Config_destroy(aTHX_ &c -> Config) ;
Embperl__Component__Param_destroy(aTHX_ &c -> Param) ;
Embperl__Component_destroy(aTHX_ c) ;
pHV = SvRV (c -> _perlsv) ;
if ((mg = mg_find (pHV, '~')))
*((tComponent **)(mg -> mg_ptr)) = &NullRequest.Component ;
pHV = SvRV (c -> Config._perlsv) ;
if ((mg = mg_find (pHV, '~')))
*((tComponentConfig **)(mg -> mg_ptr)) = &NullRequest.Component.Config ;
pHV = SvRV (c -> Param._perlsv) ;
if ((mg = mg_find (pHV, '~')))
*((tComponentParam **)(mg -> mg_ptr)) = &NullRequest.Component.Param ;
SvREFCNT_dec (c -> Config._perlsv) ;
SvREFCNT_dec (c -> Param._perlsv) ;
SvREFCNT_dec (c -> _perlsv) ;
if (c == &r -> Component && c -> pPrev)
{ /* we have a previous component, so let restore it */
tComponent * pPrev = c -> pPrev;
memcpy (c, pPrev, sizeof (*c)) ;
/* adjust pointer in perl magic */
pHV = SvRV (c -> _perlsv) ;
if ((mg = mg_find (pHV, '~')))
*((tComponent **)(mg -> mg_ptr)) = c ;
pHV = SvRV (c -> Config._perlsv) ;
if ((mg = mg_find (pHV, '~')))
*((tComponentConfig **)(mg -> mg_ptr)) = &c -> Config ;
pHV = SvRV (c -> Param._perlsv) ;
if ((mg = mg_find (pHV, '~')))
*((tComponentParam **)(mg -> mg_ptr)) = &c -> Param ;
}
else
{
c -> _perlsv = NULL ;
}
return ok ;
}
/*---------------------------------------------------------------------------
* embperl_CleanupRequest
*/
/*!
*
* \_en
* cleanup request
* \endif
*
* \_de
* Das Requestobjekt aufr?umen
* \endif
*
* ------------------------------------------------------------------------ */
int embperl_CleanupRequest (/*in*/ tReq * r)
{
epTHX_
int i ;
HE * pEntry ;
I32 l ;
tApp * pApp = r -> pApp ;
SV * pHV ;
MAGIC * mg;
dSP ;
hv_iterinit (r -> pCleanupPackagesHV) ;
while ((pEntry = hv_iternext (r -> pCleanupPackagesHV)))
{
char * sPackage = hv_iterkey (pEntry, &l) ;
ClearSymtab (r, sPackage, r -> Config.bDebug & dbgShowCleanup) ;
}
tainted = 0 ;
sv_setsv(r -> pThread -> pReqRV, &sv_undef) ;
while (r -> Component._perlsv)
embperl_CleanupComponent(&r -> Component) ;
if (r -> nSessionMgnt)
{
SPAGAIN ;
PUSHMARK(sp);
XPUSHs(pApp -> pAppObj);
PUTBACK;
perl_call_method ("cleanup", G_DISCARD) ;
SPAGAIN ;
PUSHMARK(sp);
XPUSHs(pApp -> pUserObj);
PUTBACK;
perl_call_method ("cleanup", G_DISCARD) ;
SPAGAIN ;
PUSHMARK(sp);
XPUSHs(pApp -> pStateObj);
PUTBACK;
perl_call_method ("cleanup", G_DISCARD) ;
SPAGAIN ;
}
hv_clear (r -> pThread -> pHeaderHash) ;
hv_clear (r -> pThread -> pInputHash) ;
av_clear (r -> pThread -> pFormArray) ;
hv_clear (r -> pThread -> pFormHash) ;
hv_clear (r -> pThread -> pFormSplitHash) ;
/*
for (i = 0 ; i <= av_len (r -> pDomTreeAV); i++)
{
SV ** ppSV = av_fetch (r -> pDomTreeAV, i, 0) ;
SV * pSV = * ppSV ;
lprintf (r -> pApp, "r -> pDomTreeAV DomTree #%d type = %d cnt=%d n=%d\n", i, SvTYPE(pSV), SvREFCNT(pSV), SvIVX(pSV)) ;
}
*/
av_clear (r -> pDomTreeAV) ;
SvREFCNT_dec (r -> pDomTreeAV) ;
for (i = 0 ; i <= av_len (r -> pCleanupAV); i++)
{
SV ** ppSV = av_fetch (r -> pCleanupAV, i, 0) ;
SV * pSV = * ppSV ;
/*
if (SvROK(pSV))
lprintf (r -> pApp, "r -> pCleanupAV DomTree #%d type = %d cnt=%d n=%d\n", i, SvTYPE(SvRV(pSV)), SvREFCNT(SvRV(pSV)), SvIVX(SvRV(pSV))) ;
*/
if (SvROK(pSV))
sv_setsv (SvRV(pSV), &sv_undef) ;
}
av_clear (r -> pCleanupAV) ;
Cache_CleanupRequest (r) ;
if (SvREFCNT(SvRV(r -> Config._perlsv)) != 1)
{
char buf[20] ;
sprintf (buf, "%d", (int)SvREFCNT(SvRV(r -> Config._perlsv)) - 1) ;
LogErrorParam (r -> pApp, rcRefcntNotOne, buf, "request.config") ;
}
if (SvREFCNT(SvRV(r -> Param._perlsv)) != 1)
{
char buf[20] ;
sprintf (buf, "%d", (int)SvREFCNT(SvRV(r -> Param._perlsv)) - 1) ;
LogErrorParam (r -> pApp, rcRefcntNotOne, buf, "request.param") ;
}
/*
if (SvREFCNT(SvRV(r -> _perlsv)) != 1)
{
char buf[20] ;
sprintf (buf, "%d", SvREFCNT(SvRV(r -> _perlsv)) - 1) ;
LogErrorParam (r -> pApp, rcRefcntNotOne, buf, "request") ;
}
*/
/* cleanup errarray manualy, to avoid segv incase error in destroy */
SvREFCNT_dec (r -> pErrArray) ;
r -> pErrArray = NULL ;
Embperl__Req__Config_destroy(aTHX_ &r -> Config) ;
Embperl__Req__Param_destroy(aTHX_ &r -> Param) ;
Embperl__Req_destroy(aTHX_ r) ;
pHV = SvRV (r -> _perlsv) ;
if ((mg = mg_find (pHV, '~')))
*((tReq **)(mg -> mg_ptr)) = &NullRequest ;
pHV = SvRV (r -> Config._perlsv) ;
if ((mg = mg_find (pHV, '~')))
*((tReqConfig **)(mg -> mg_ptr)) = &NullRequest.Config ;
pHV = SvRV (r -> Param._perlsv) ;
if ((mg = mg_find (pHV, '~')))
*((tReqParam **)(mg -> mg_ptr)) = &NullRequest.Param ;
SvREFCNT_dec (r -> Config._perlsv) ;
SvREFCNT_dec (r -> Param._perlsv) ;
SvREFCNT_dec (r -> _perlsv) ;
ep_destroy_pool (r -> pPool) ;
sv_setpv(ERRSV,"");
if (r -> Config.bDebug)
DomStats (r -> pApp) ;
r -> pThread -> pCurrReq = r -> pPrevReq ;
r -> pApp -> pCurrReq = r -> pPrevReq ;
if (r -> pPrevReq)
sv_setsv(r -> pThread -> pReqRV, r -> pPrevReq -> _perlsv) ;
return ok ;
}
/*---------------------------------------------------------------------------
* embperl_SetupOutput
*/
/*!
*
* \_en
* setup data for component output object
* \endif
*
* \_de
* Initialisiert das Component-Ausgabe Objekt
* \endif
*
* ------------------------------------------------------------------------ */
int embperl_SetupOutput (/*in*/ tReq * r,
/*in*/tComponent * c)
{
epTHX_
int rc ;
SV * pSV ;
SV * pRV ;
tComponentOutput * pOutput ;
tMemPool * pPool ;
if (!c -> Param.pOutput && !c -> Param.sOutputfile && c -> pPrev && !r -> Component.pImportStash)
{ /* this component uses the main output object */
c -> pOutput = c -> pPrev -> pOutput ;
return ok ;
}
pPool = ep_make_sub_pool (r -> pPool) ;
tainted = 0 ;
epxs_Embperl__Component__Output_create_obj(pOutput,pSV,pRV,ep_palloc(pPool,sizeof(tComponentOutput))) ;
tainted = 0 ;
pOutput -> pPool = pPool ;
c -> pOutput = pOutput ;
if (r -> Component.pImportStash)
pOutput -> bDisableOutput = 1 ;
else if (c -> Param.pOutput)
{
if ((rc = OpenOutput (r, "")) != ok)
return rc ;
}
else
{
if ((rc = OpenOutput (r, embperl_File2Abs(r, pOutput -> pPool, c -> Param.sOutputfile))) != ok)
return rc ;
}
return ok ;
}
/*---------------------------------------------------------------------------
* embperl_SetupComponent
*/
/*!
*
* \_en
* setup data for component object
* \endif
*
* \_de
* Initialisiert das Component-Objekt
* \endif
*
* ------------------------------------------------------------------------ */
int embperl_SetupComponent (/*in*/ tReq * r,
/*in*/ SV * pPerlParam,
/*out*/tComponent * * ppComponent)
{
int rc ;
SV * pComponentSV ;
SV * pComponentRV ;
SV * pSV ;
SV * pRV ;
tComponent * c ;
tComponentParam * pParam ;
tComponentConfig * pConfig ;
epTHX_
tComponent * pPrev = NULL ;
char * p ;
HV * pParamHV = NULL ;
if (r -> Component._perlsv)
{ /* we have already a component, so let safe it first */
SV * pHV ;
MAGIC * mg ;
pPrev = ep_palloc(r->pPool,sizeof(*pPrev)) ;
memcpy (pPrev, &r -> Component, sizeof (*pPrev)) ;
/* adjust pointer in perl magic */
pHV = SvRV (pPrev -> _perlsv) ;
if ((mg = mg_find (pHV, '~')))
*((tComponent **)(mg -> mg_ptr)) = pPrev ;
pHV = SvRV (pPrev -> Config._perlsv) ;
if ((mg = mg_find (pHV, '~')))
*((tComponentConfig **)(mg -> mg_ptr)) = &pPrev -> Config ;
pHV = SvRV (pPrev -> Param._perlsv) ;
if ((mg = mg_find (pHV, '~')))
*((tComponentParam **)(mg -> mg_ptr)) = &pPrev -> Param ;
}
if (pPerlParam && SvROK(pPerlParam))
pParamHV = (HV *)SvRV(pPerlParam) ;
epxs_Embperl__Component_create_obj(c,pComponentSV, pComponentRV,&r->Component) ;
epxs_Embperl__Component__Param_create_obj(pParam,pSV, pRV,&r->Component.Param) ;
epxs_Embperl__Component__Config_create_obj(pConfig,pSV, pRV,&r->Component.Config) ;
r -> Component.pPrev = pPrev ;
c -> pPool = r -> pPool ;
pParam -> pPool = r -> pPool ;
pConfig -> pPool = r -> pPool ;
c -> Param.nImport = -1 ;
c -> Param.nFirstLine = 1 ;
c -> pReq = r ;
#ifdef APACHE
if (r -> pApacheReq)
{
embperl_GetApacheComponentConfig (r, r -> pPool, r -> pApacheConfig, &c -> Config) ;
}
else
#endif
{
bool bUseEnv = 0 ;
bool bUseRedirectEnv = 0 ;
if (pParamHV)
{
bUseEnv = (bool)GetHashValueInt (aTHX_ pParamHV, "use_env", 0) ;
bUseRedirectEnv = (bool)GetHashValueInt (aTHX_ pParamHV, "use_redirect_env", 0) ;
}
embperl_GetCGIComponentConfig (r, r -> pPool, &c -> Config, bUseEnv, bUseRedirectEnv, 1) ;
}
if (pPrev)
c -> Config.bOptions &= ~optReturnError ;
if (pParamHV)
{
Embperl__Component__Config_new_init (aTHX_ &c -> Config, (SV *)pParamHV, 0) ;
Embperl__Component__Param_new_init (aTHX_ &c -> Param, (SV *)pParamHV, 0) ;
}
c -> sCWD = pPrev?pPrev -> sCWD:r -> sInitialCWD ;
if (c -> sCWD == NULL)
c -> sCWD = "" ;
NewEscMode (r, NULL) ;
c -> bEscModeSet = 0 ;
if (c -> Param.nImport < 0 && (c -> Param.sObject || c -> Param.sISA))
c -> Param.nImport = 0 ;
if (c -> Param.nImport >= 0)
{
char code[40] ;
SV * pSVImport ;
STRLEN l ;
sprintf (code, "caller(%d)", c -> Param.nImport>0?c -> Param.nImport:1) ;
/* there is no c api to the caller function, eval it... */
pSVImport = perl_eval_pv(code, 0) ;
if (!SvOK(pSVImport))
{
if (c -> Param.nImport == 0)
c -> sImportPackage = "main" ;
else
{
LogError (r, rcImportStashErr) ;
c -> sImportPackage = NULL ;
}
}
else
c -> sImportPackage = ep_pstrdup(r -> pPool, SvPV (pSVImport, l)) ;
if (c -> sImportPackage)
{
if ((c -> pImportStash = gv_stashpv (c -> sImportPackage, 0)) == NULL)
{
strncpy (r -> errdat1, c -> sImportPackage, sizeof (r -> errdat1) - 1);
LogError (r, rcImportStashErr) ;
}
SvREFCNT_inc(c -> pImportStash) ;
}
}
c -> nSourceline = pParam -> nFirstLine ;
if (!pParam -> sInputfile)
{
if (pParam -> sISA)
pParam -> sInputfile = pParam -> sISA ;
else if (pParam -> sObject)
pParam -> sInputfile = pParam -> sObject ;
else
{
if (pPrev)
pParam -> sInputfile = pPrev -> sSourcefile ;
if (!pParam -> sInputfile)
pParam -> sInputfile = r -> Param.sFilename ;
}
}
else if ((p = strchr(pParam -> sInputfile, '#')))
{
pParam -> sSub = p + 1 ;
if (p == pParam -> sInputfile && c -> pPrev)
pParam -> sInputfile = c -> pPrev -> sSourcefile ;
else
*p = '\0' ;
}
if (!pParam -> sInputfile || !*pParam -> sInputfile || strcmp(pParam -> sInputfile, "*") == 0)
pParam -> sInputfile = r -> Param.sFilename ;
else if (strcmp(pParam -> sInputfile, "../*") == 0)
{
#ifdef WIN32
char * p = strrchr(r -> Param.sFilename, '\\') ;
if (!p)
p = strrchr(r -> Param.sFilename, '/') ;
#else
char * p = strrchr(r -> Param.sFilename, '/') ;
#endif
if (!p)
p = r -> Param.sFilename ;
else
p++ ;
pParam -> sInputfile = ep_pstrcat(r -> pPool, "../", p, NULL) ;
}
*ppComponent = c ;
if (!pParam -> sInputfile)
rc = rcMissingInput ;
else
rc = embperl_SetupOutput (r, c) ;
if (rc != ok)
LogError (r, rc) ;
return rc ;
}
/*---------------------------------------------------------------------------
* embperl_InitRequest
*/
/*!
*
* \_en
* Initialize the Thread and Application object and if available return the
* Apache configuration data
* \endif
*
* \_de
* Initialisiert das Thread und Application Objekt und leifert, soweit vorhanden,
* die Apache Konfiguration
* \endif
*
* ------------------------------------------------------------------------ */
int embperl_InitAppForRequest (/*in*/ pTHX_
/*in*/ SV * pApacheReqSV,
/*in*/ SV * pPerlParam,
/*out*/tThreadData * * ppThread,
/*out*/tApp * * ppApp,
/*out*/tApacheDirConfig * * ppApacheCfg)
{
int rc ;
tThreadData * pThread ;
tApp * pApp ;
tApacheDirConfig * pApacheCfg = NULL ;
/* get our thread object */
if ((rc = embperl_SetupThread (aTHX_ &pThread)) != ok)
{
LogError (NULL, rc) ;
return rc ;
}
#ifdef APACHE
if (pApacheReqSV && SvROK (pApacheReqSV))
{
request_rec * ap_r = (request_rec *)SvIV((SV*)SvRV(pApacheReqSV));
embperl_GetApacheConfig (pThread, ap_r, ap_r -> server, &pApacheCfg) ;
}
#endif
/* get the application object */
if ((rc = embperl_SetupApp (aTHX_ pThread, pApacheCfg, pPerlParam, &pApp)) != ok)
{
LogError (NULL, rc) ;
return rc ;
}
*ppThread = pThread ;
*ppApp = pApp ;
*ppApacheCfg = pApacheCfg ;
return ok ;
}
/*---------------------------------------------------------------------------
* embperl_InitRequest
*/
/*!
*
* \_en
* Initialize all necessary data structures to start a request like thread,
* application and request object
* \endif
*
* \_de
* Initialisiert alle n?tigen Datenstrukturen um den Request zu starten, wie
* Thread-, Applikcation und Request-Objekt.
* \endif
*
* ------------------------------------------------------------------------ */
int embperl_InitRequest (/*in*/ pTHX_
/*in*/ SV * pApacheReqSV,
/*in*/ SV * pPerlParam,
/*out*/tReq * * ppReq)
{
int rc ;
tThreadData * pThread ;
tApp * pApp ;
tReq * r ;
tApacheDirConfig * pApacheCfg = NULL ;
/* get our thread & Application object */
if ((rc = embperl_InitAppForRequest (aTHX_
pApacheReqSV,
pPerlParam,
&pThread,
&pApp,
&pApacheCfg)) != ok)
{
LogError (NULL, rc) ;
return rc ;
}
/* and setup the request object */
if ((rc = embperl_SetupRequest (aTHX_ pApacheReqSV, pApp, pApacheCfg, pPerlParam, &r)) != ok)
{
LogErrorParam (pApp, rc, NULL, NULL) ;
return rc ;
}
r -> pApacheConfig = pApacheCfg ;
*ppReq = r ;
if (r -> Config.pAllow || r -> Config.pUriMatch)
{
SV * args[1] ;
SV * pRet ;
STRLEN l ;
if (r -> Param.sUri && *r -> Param.sUri)
args[0] = newSVpv (r -> Param.sUri, 0) ;
else if (r -> Param.sFilename && *r -> Param.sFilename)
args[0] = newSVpv (r -> Param.sFilename, 0) ;
else if (pPerlParam && SvROK(pPerlParam))
args[0] = (SV *)GetHashValueSVinc (r, (HV *)SvRV(pPerlParam), "inputfile", &sv_undef) ;
else
{
LogError (r, rcCannotCheckUri) ;
return rcCannotCheckUri ;
}
if (r -> Config.pAllow)
{
CallStoredCV (r, "ALLOW", r -> Config.pAllow, 1, args, 0, &pRet) ;
if (pRet && !SvTRUE(pRet))
{
strncpy (r -> errdat1, SvPV(args[0], l), sizeof(r -> errdat1) - 1) ;
SvREFCNT_dec(args[0]) ;
if (pRet)
SvREFCNT_dec(pRet) ;
LogError (r, rcForbidden) ;
return rcForbidden ;
}
if (pRet)
SvREFCNT_dec(pRet) ;
}
if (r -> Config.pUriMatch)
{
CallStoredCV (r, "URIMATCH", r -> Config.pUriMatch, 1, args, 0, &pRet) ;
if (pRet && !SvTRUE(pRet))
{
strncpy (r -> errdat1, SvPV(args[0], l), sizeof(r -> errdat1) - 1) ;
SvREFCNT_dec(args[0]) ;
if (pRet)
SvREFCNT_dec(pRet) ;
return rcDecline ;
}
if (pRet)
SvREFCNT_dec(pRet) ;
}
SvREFCNT_dec(args[0]) ;
}
return ok ;
}
int embperl_InitRequestComponent (/*in*/ pTHX_
/*in*/ SV * pApacheReqSV,
/*in*/ SV * pPerlParam,
/*out*/tReq * * ppReq)
{
int rc ;
tComponent * pComponent ;
if ((rc = embperl_InitRequest (aTHX_ pApacheReqSV, pPerlParam, ppReq)) != ok)
return rc ;
return embperl_SetupComponent (*ppReq, pPerlParam, &pComponent) ;
}
|