You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1954 lines
55 KiB

23 years ago
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 4 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2003 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.0 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_0.txt. |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
  16. | Stig Sther Bakken <ssb@php.net> |
  17. | David Sklar <sklar@student.net> |
  18. +----------------------------------------------------------------------+
  19. */
  20. /* $Id$ */
  21. #include "php_apache_http.h"
  22. #if defined(PHP_WIN32) || defined(NETWARE)
  23. #include "zend.h"
  24. #include "ap_compat.h"
  25. #else
  26. #include "build-defs.h"
  27. #endif
  28. #ifdef ZTS
  29. int php_apache_info_id;
  30. #else
  31. php_apache_info_struct php_apache_info;
  32. #endif
  33. #define SECTION(name) PUTS("<H2 align=\"center\">" name "</H2>\n")
  34. #undef offsetof
  35. #define offsetof(s_type,field) ((size_t)&(((s_type*)0)->field))
  36. extern module *top_module;
  37. extern module **ap_loaded_modules;
  38. static int le_apachereq;
  39. static zend_class_entry *apacherequest_class_entry;
  40. static void apache_table_to_zval(table *, int safe_mode, zval *return_value);
  41. PHP_FUNCTION(virtual);
  42. PHP_FUNCTION(apache_request_headers);
  43. PHP_FUNCTION(apache_response_headers);
  44. PHP_FUNCTION(apachelog);
  45. PHP_FUNCTION(apache_note);
  46. PHP_FUNCTION(apache_lookup_uri);
  47. PHP_FUNCTION(apache_child_terminate);
  48. PHP_FUNCTION(apache_setenv);
  49. PHP_FUNCTION(apache_get_version);
  50. PHP_FUNCTION(apache_get_modules);
  51. PHP_MINFO_FUNCTION(apache);
  52. function_entry apache_functions[] = {
  53. PHP_FE(virtual, NULL)
  54. PHP_FE(apache_request_headers, NULL)
  55. PHP_FE(apache_note, NULL)
  56. PHP_FE(apache_lookup_uri, NULL)
  57. PHP_FE(apache_child_terminate, NULL)
  58. PHP_FE(apache_setenv, NULL)
  59. PHP_FE(apache_response_headers, NULL)
  60. PHP_FE(apache_get_version, NULL)
  61. PHP_FE(apache_get_modules, NULL)
  62. PHP_FALIAS(getallheaders, apache_request_headers, NULL)
  63. {NULL, NULL, NULL}
  64. };
  65. /* {{{ php_apache ini entries
  66. */
  67. PHP_INI_BEGIN()
  68. STD_PHP_INI_ENTRY("xbithack", "0", PHP_INI_ALL, OnUpdateLong, xbithack, php_apache_info_struct, php_apache_info)
  69. STD_PHP_INI_ENTRY("engine", "1", PHP_INI_ALL, OnUpdateLong, engine, php_apache_info_struct, php_apache_info)
  70. STD_PHP_INI_ENTRY("last_modified", "0", PHP_INI_ALL, OnUpdateLong, last_modified, php_apache_info_struct, php_apache_info)
  71. STD_PHP_INI_ENTRY("child_terminate", "0", PHP_INI_ALL, OnUpdateLong, terminate_child, php_apache_info_struct, php_apache_info)
  72. PHP_INI_END()
  73. /* }}} */
  74. static void php_apache_globals_ctor(php_apache_info_struct *apache_globals TSRMLS_DC)
  75. {
  76. apache_globals->in_request = 0;
  77. }
  78. #define APREQ_GET_THIS(ZVAL) if (NULL == (ZVAL = getThis())) { \
  79. php_error(E_WARNING, "%s(): underlying ApacheRequest object missing", \
  80. get_active_function_name(TSRMLS_C)); \
  81. RETURN_FALSE; \
  82. }
  83. #define APREQ_GET_REQUEST(ZVAL, R) APREQ_GET_THIS(ZVAL); \
  84. R = get_apache_request(ZVAL TSRMLS_CC)
  85. static void php_apache_request_free(zend_rsrc_list_entry *rsrc TSRMLS_DC)
  86. {
  87. zval *z = (zval *)rsrc->ptr;
  88. /* fprintf(stderr, "%s() %p\n", __FUNCTION__, z); */
  89. zval_ptr_dtor(&z);
  90. }
  91. static request_rec *get_apache_request(pval *z TSRMLS_DC)
  92. {
  93. request_rec *r;
  94. zval **addr;
  95. if (NULL == z) {
  96. php_error(E_WARNING, "get_apache_request() invalid wrapper passed");
  97. return NULL;
  98. }
  99. if (Z_TYPE_P(z) != IS_OBJECT) {
  100. php_error(E_WARNING, "%s(): wrapper is not an object", get_active_function_name(TSRMLS_C));
  101. return NULL;
  102. }
  103. if (zend_hash_index_find(Z_OBJPROP_P(z), 0, (void **)&addr) == FAILURE) {
  104. php_error(E_WARNING, "%s(): underlying object missing", get_active_function_name(TSRMLS_C));
  105. return NULL;
  106. }
  107. r = (request_rec *)Z_LVAL_PP(addr);
  108. if (!r) {
  109. php_error(E_WARNING, "%s(): request_rec invalid", get_active_function_name(TSRMLS_C));
  110. return NULL;
  111. }
  112. return r;
  113. }
  114. /* {{{ php_apache_request_new(request_rec *r)
  115. * create a new zval-instance for ApacheRequest that wraps request_rec
  116. */
  117. zval *php_apache_request_new(request_rec *r)
  118. {
  119. zval *req;
  120. zval *addr;
  121. TSRMLS_FETCH();
  122. MAKE_STD_ZVAL(addr);
  123. Z_TYPE_P(addr) = IS_LONG;
  124. Z_LVAL_P(addr) = (int) r;
  125. MAKE_STD_ZVAL(req);
  126. object_init_ex(req, apacherequest_class_entry);
  127. zend_hash_index_update(Z_OBJPROP_P(req), 0, &addr, sizeof(zval *), NULL);
  128. return req;
  129. }
  130. /* }}} */
  131. /* {{{ apache_request_read_string_slot()
  132. */
  133. static void apache_request_read_string_slot(int offset, INTERNAL_FUNCTION_PARAMETERS)
  134. {
  135. zval *id;
  136. request_rec *r;
  137. char *s;
  138. if (ZEND_NUM_ARGS() > 0) {
  139. WRONG_PARAM_COUNT;
  140. }
  141. APREQ_GET_REQUEST(id, r);
  142. s = *(char **)((char*)r + offset);
  143. if (s)
  144. RETURN_STRING(s, 1);
  145. RETURN_EMPTY_STRING();
  146. }
  147. /* }}} */
  148. /* {{{ apache_request_string_slot()
  149. */
  150. static void apache_request_string_slot(int offset, INTERNAL_FUNCTION_PARAMETERS)
  151. {
  152. zval *id, **new_value;
  153. request_rec *r;
  154. char *old_value;
  155. char **target;
  156. APREQ_GET_REQUEST(id, r);
  157. target = (char **)((char*)r + offset);
  158. old_value = *target;
  159. switch (ZEND_NUM_ARGS()) {
  160. case 0:
  161. break;
  162. case 1:
  163. if (zend_get_parameters_ex(1, &new_value) == FAILURE) {
  164. RETURN_FALSE;
  165. }
  166. convert_to_string_ex(new_value);
  167. *target = ap_pstrdup(r->pool, Z_STRVAL_PP(new_value));
  168. break;
  169. default:
  170. WRONG_PARAM_COUNT;
  171. break;
  172. }
  173. if (old_value)
  174. RETURN_STRING(old_value, 1);
  175. RETURN_EMPTY_STRING();
  176. }
  177. /* }}} */
  178. /* {{{ apache_request_read_int_slot()
  179. */
  180. static void apache_request_read_int_slot(int offset, INTERNAL_FUNCTION_PARAMETERS)
  181. {
  182. zval *id;
  183. request_rec *r;
  184. long l;
  185. if (ZEND_NUM_ARGS() > 0) {
  186. WRONG_PARAM_COUNT;
  187. }
  188. APREQ_GET_REQUEST(id, r);
  189. l = *(long *)((char*)r + offset);
  190. RETURN_LONG(l);
  191. }
  192. /* }}} */
  193. /* {{{ apache_request_int_slot()
  194. */
  195. static void apache_request_int_slot(int offset, INTERNAL_FUNCTION_PARAMETERS)
  196. {
  197. zval *id, **new_value;
  198. request_rec *r;
  199. long old_value;
  200. long *target;
  201. APREQ_GET_REQUEST(id, r);
  202. target = (long *)((char*)r + offset);
  203. old_value = *target;
  204. switch (ZEND_NUM_ARGS()) {
  205. case 0:
  206. break;
  207. case 1:
  208. if (zend_get_parameters_ex(1, &new_value) == FAILURE) {
  209. RETURN_FALSE;
  210. }
  211. convert_to_long_ex(new_value);
  212. *target = Z_LVAL_PP(new_value);
  213. break;
  214. default:
  215. WRONG_PARAM_COUNT;
  216. break;
  217. }
  218. RETURN_LONG(old_value);
  219. }
  220. /* }}} */
  221. /* {{{ access string slots of request rec
  222. */
  223. /* {{{ proto string $request->filename([string new_filename])
  224. */
  225. PHP_FUNCTION(apache_request_filename)
  226. {
  227. apache_request_string_slot(offsetof(request_rec, filename), INTERNAL_FUNCTION_PARAM_PASSTHRU);
  228. }
  229. /* }}} */
  230. /* {{{ proto string $request->uri([string new_uri])
  231. */
  232. PHP_FUNCTION(apache_request_uri)
  233. {
  234. apache_request_string_slot(offsetof(request_rec, uri), INTERNAL_FUNCTION_PARAM_PASSTHRU);
  235. }
  236. /* }}} */
  237. /* {{{ proto string $request->unparsed_uri([string new_unparsed_uri])
  238. */
  239. PHP_FUNCTION(apache_request_unparsed_uri)
  240. {
  241. apache_request_string_slot(offsetof(request_rec, unparsed_uri), INTERNAL_FUNCTION_PARAM_PASSTHRU);
  242. }
  243. /* }}} */
  244. /* {{{ proto string $request->path_info([string new_path_info])
  245. */
  246. PHP_FUNCTION(apache_request_path_info)
  247. {
  248. apache_request_string_slot(offsetof(request_rec, path_info), INTERNAL_FUNCTION_PARAM_PASSTHRU);
  249. }
  250. /* }}} */
  251. /* {{{ proto string $request->args([string new_args])
  252. */
  253. PHP_FUNCTION(apache_request_args)
  254. {
  255. apache_request_string_slot(offsetof(request_rec, args), INTERNAL_FUNCTION_PARAM_PASSTHRU);
  256. }
  257. /* }}} */
  258. /* {{{ proto string $request->boundary()
  259. */
  260. PHP_FUNCTION(apache_request_boundary)
  261. {
  262. apache_request_read_string_slot(offsetof(request_rec, boundary), INTERNAL_FUNCTION_PARAM_PASSTHRU);
  263. }
  264. /* }}} */
  265. /* {{{ proto string $request->content_type([string new_type])
  266. */
  267. PHP_FUNCTION(apache_request_content_type)
  268. {
  269. apache_request_string_slot(offsetof(request_rec, content_type), INTERNAL_FUNCTION_PARAM_PASSTHRU);
  270. }
  271. /* }}} */
  272. /* {{{ proto string $request->content_encoding([string new_encoding])
  273. */
  274. PHP_FUNCTION(apache_request_content_encoding)
  275. {
  276. apache_request_string_slot(offsetof(request_rec, content_encoding), INTERNAL_FUNCTION_PARAM_PASSTHRU);
  277. }
  278. /* }}} */
  279. /* {{{ proto string $request->handler([string new_handler])
  280. */
  281. PHP_FUNCTION(apache_request_handler)
  282. {
  283. apache_request_string_slot(offsetof(request_rec, handler), INTERNAL_FUNCTION_PARAM_PASSTHRU);
  284. }
  285. /* }}} */
  286. /* {{{ proto string $request->the_request()
  287. */
  288. PHP_FUNCTION(apache_request_the_request)
  289. {
  290. apache_request_read_string_slot(offsetof(request_rec, the_request), INTERNAL_FUNCTION_PARAM_PASSTHRU);
  291. }
  292. /* }}} */
  293. /* {{{ proto string $request->protocol()
  294. */
  295. PHP_FUNCTION(apache_request_protocol)
  296. {
  297. apache_request_read_string_slot(offsetof(request_rec, protocol), INTERNAL_FUNCTION_PARAM_PASSTHRU);
  298. }
  299. /* }}} */
  300. /* {{{ proto string $request->hostname()
  301. */
  302. PHP_FUNCTION(apache_request_hostname)
  303. {
  304. apache_request_read_string_slot(offsetof(request_rec, hostname), INTERNAL_FUNCTION_PARAM_PASSTHRU);
  305. }
  306. /* }}} */
  307. /* {{{ proto string $request->status_line([string new_status_line])
  308. */
  309. PHP_FUNCTION(apache_request_status_line)
  310. {
  311. apache_request_string_slot(offsetof(request_rec, status_line), INTERNAL_FUNCTION_PARAM_PASSTHRU);
  312. }
  313. /* }}} */
  314. /* {{{ proto string $request->method()
  315. */
  316. PHP_FUNCTION(apache_request_method)
  317. {
  318. apache_request_read_string_slot(offsetof(request_rec, method), INTERNAL_FUNCTION_PARAM_PASSTHRU);
  319. }
  320. /* }}} */
  321. /* }}} access string slots of request rec */
  322. /* {{{ access int slots of request_rec
  323. */
  324. /* {{{ proto int $request->proto_num()
  325. */
  326. PHP_FUNCTION(apache_request_proto_num)
  327. {
  328. apache_request_read_int_slot(offsetof(request_rec, proto_num), INTERNAL_FUNCTION_PARAM_PASSTHRU);
  329. }
  330. /* }}} */
  331. /* {{{ proto int $request->assbackwards()
  332. */
  333. PHP_FUNCTION(apache_request_assbackwards)
  334. {
  335. apache_request_read_int_slot(offsetof(request_rec, assbackwards), INTERNAL_FUNCTION_PARAM_PASSTHRU);
  336. }
  337. /* }}} */
  338. /* {{{ proto int $request->proxyreq([int new_proxyreq])
  339. */
  340. PHP_FUNCTION(apache_request_proxyreq)
  341. {
  342. apache_request_int_slot(offsetof(request_rec, proxyreq), INTERNAL_FUNCTION_PARAM_PASSTHRU);
  343. }
  344. /* }}} */
  345. /* {{{ proto int $request->chunked()
  346. */
  347. PHP_FUNCTION(apache_request_chunked)
  348. {
  349. apache_request_read_int_slot(offsetof(request_rec, chunked), INTERNAL_FUNCTION_PARAM_PASSTHRU);
  350. }
  351. /* }}} */
  352. /* {{{ proto int $request->header_only()
  353. */
  354. PHP_FUNCTION(apache_request_header_only)
  355. {
  356. apache_request_read_int_slot(offsetof(request_rec, header_only), INTERNAL_FUNCTION_PARAM_PASSTHRU);
  357. }
  358. /* }}} */
  359. /* {{{ proto int $request->request_time()
  360. */
  361. PHP_FUNCTION(apache_request_request_time)
  362. {
  363. apache_request_read_int_slot(offsetof(request_rec, request_time), INTERNAL_FUNCTION_PARAM_PASSTHRU);
  364. }
  365. /* }}} */
  366. /* {{{ proto int $request->status([int new_status])
  367. */
  368. PHP_FUNCTION(apache_request_status)
  369. {
  370. apache_request_int_slot(offsetof(request_rec, status), INTERNAL_FUNCTION_PARAM_PASSTHRU);
  371. }
  372. /* }}} */
  373. /* {{{ proto int $request->method_number([int method_number])
  374. */
  375. PHP_FUNCTION(apache_request_method_number)
  376. {
  377. apache_request_read_int_slot(offsetof(request_rec, method_number), INTERNAL_FUNCTION_PARAM_PASSTHRU);
  378. }
  379. /* }}} */
  380. /* {{{ proto int $request->allowed([int allowed])
  381. */
  382. PHP_FUNCTION(apache_request_allowed)
  383. {
  384. apache_request_int_slot(offsetof(request_rec, allowed), INTERNAL_FUNCTION_PARAM_PASSTHRU);
  385. }
  386. /* }}} */
  387. /* {{{ proto int $request->bytes_sent()
  388. */
  389. PHP_FUNCTION(apache_request_bytes_sent)
  390. {
  391. apache_request_read_int_slot(offsetof(request_rec, bytes_sent), INTERNAL_FUNCTION_PARAM_PASSTHRU);
  392. }
  393. /* }}} */
  394. /* {{{ proto int $request->mtime()
  395. */
  396. PHP_FUNCTION(apache_request_mtime)
  397. {
  398. apache_request_read_int_slot(offsetof(request_rec, mtime), INTERNAL_FUNCTION_PARAM_PASSTHRU);
  399. }
  400. /* }}} */
  401. /* {{{ proto int $request->content_length([int new_content_length])
  402. */
  403. PHP_FUNCTION(apache_request_content_length)
  404. {
  405. zval *id, **zlen;
  406. request_rec *r;
  407. if (ZEND_NUM_ARGS() == 0) {
  408. apache_request_read_int_slot(offsetof(request_rec, clength), INTERNAL_FUNCTION_PARAM_PASSTHRU);
  409. }
  410. else if (ZEND_NUM_ARGS() > 1) {
  411. WRONG_PARAM_COUNT;
  412. }
  413. else {
  414. if (zend_get_parameters_ex(1, &zlen) == FAILURE) {
  415. RETURN_FALSE;
  416. }
  417. APREQ_GET_REQUEST(id, r);
  418. convert_to_long_ex(zlen);
  419. (void)ap_set_content_length(r, Z_LVAL_PP(zlen));
  420. RETURN_TRUE;
  421. }
  422. }
  423. /* }}} */
  424. /* {{{ proto int $request->remaining()
  425. */
  426. PHP_FUNCTION(apache_request_remaining)
  427. {
  428. apache_request_read_int_slot(offsetof(request_rec, remaining), INTERNAL_FUNCTION_PARAM_PASSTHRU);
  429. }
  430. /* }}} */
  431. /* {{{ proto int $request->no_cache()
  432. */
  433. PHP_FUNCTION(apache_request_no_cache)
  434. {
  435. apache_request_int_slot(offsetof(request_rec, no_cache), INTERNAL_FUNCTION_PARAM_PASSTHRU);
  436. }
  437. /* }}} */
  438. /* {{{ proto int $request->no_local_copy()
  439. */
  440. PHP_FUNCTION(apache_request_no_local_copy)
  441. {
  442. apache_request_int_slot(offsetof(request_rec, no_local_copy), INTERNAL_FUNCTION_PARAM_PASSTHRU);
  443. }
  444. /* }}} */
  445. /* {{{ proto int $request->read_body()
  446. */
  447. PHP_FUNCTION(apache_request_read_body)
  448. {
  449. apache_request_int_slot(offsetof(request_rec, read_body), INTERNAL_FUNCTION_PARAM_PASSTHRU);
  450. }
  451. /* }}} */
  452. /* }}} access int slots of request_rec */
  453. /* {{{ proto array apache_request_headers_in()
  454. * fetch all incoming request headers
  455. */
  456. PHP_FUNCTION(apache_request_headers_in)
  457. {
  458. zval *id;
  459. request_rec *r;
  460. APREQ_GET_REQUEST(id, r);
  461. apache_table_to_zval(r->headers_in, 0, return_value);
  462. }
  463. /* }}} */
  464. /* {{{ add_header_to_table
  465. */
  466. static void add_header_to_table(table *t, INTERNAL_FUNCTION_PARAMETERS)
  467. {
  468. zval *first = NULL;
  469. zval *second = NULL;
  470. zval **entry, **value;
  471. char *string_key;
  472. uint string_key_len;
  473. ulong num_key;
  474. zend_bool replace = 0;
  475. HashPosition pos;
  476. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|zb", &first, &second, &replace) == FAILURE)
  477. RETURN_FALSE;
  478. if (Z_TYPE_P(first) == IS_ARRAY) {
  479. switch(ZEND_NUM_ARGS()) {
  480. case 1:
  481. case 3:
  482. zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(first), &pos);
  483. while (zend_hash_get_current_data_ex(Z_ARRVAL_P(first), (void **)&entry, &pos) == SUCCESS) {
  484. switch(zend_hash_get_current_key_ex(Z_ARRVAL_P(first), &string_key, &string_key_len, &num_key, 0, &pos)) {
  485. case HASH_KEY_IS_STRING:
  486. if (zend_hash_find(Z_ARRVAL_P(first), string_key, string_key_len, (void **)&value) == FAILURE) {
  487. zend_hash_move_forward_ex(Z_ARRVAL_P(first), &pos);
  488. continue;
  489. }
  490. if (!value) {
  491. zend_hash_move_forward_ex(Z_ARRVAL_P(first), &pos);
  492. continue;
  493. }
  494. convert_to_string_ex(value);
  495. if (replace)
  496. ap_table_set(t, string_key, Z_STRVAL_PP(value));
  497. else
  498. ap_table_merge(t, string_key, Z_STRVAL_PP(value));
  499. break;
  500. case HASH_KEY_IS_LONG:
  501. default:
  502. php_error(E_WARNING, "%s(): Can only add STRING keys to headers!", get_active_function_name(TSRMLS_C));
  503. break;
  504. }
  505. zend_hash_move_forward_ex(Z_ARRVAL_P(first), &pos);
  506. }
  507. break;
  508. default:
  509. WRONG_PARAM_COUNT;
  510. break;
  511. }
  512. }
  513. else if (Z_TYPE_P(first) == IS_STRING) {
  514. switch(ZEND_NUM_ARGS()) {
  515. case 2:
  516. case 3:
  517. convert_to_string_ex(&second);
  518. if (replace)
  519. ap_table_set(t, Z_STRVAL_P(first), Z_STRVAL_P(second));
  520. else
  521. ap_table_merge(t, Z_STRVAL_P(first), Z_STRVAL_P(second));
  522. break;
  523. default:
  524. WRONG_PARAM_COUNT;
  525. break;
  526. }
  527. }
  528. else {
  529. RETURN_FALSE;
  530. }
  531. }
  532. /* }}} */
  533. /* {{{ proto array apache_request_headers_out([{string name|array list} [, string value [, bool replace = false]]])
  534. * fetch all outgoing request headers
  535. */
  536. PHP_FUNCTION(apache_request_headers_out)
  537. {
  538. zval *id;
  539. request_rec *r;
  540. APREQ_GET_REQUEST(id, r);
  541. if (ZEND_NUM_ARGS() > 0)
  542. add_header_to_table(r->headers_out, INTERNAL_FUNCTION_PARAM_PASSTHRU);
  543. apache_table_to_zval(r->headers_out, 0, return_value);
  544. }
  545. /* }}} */
  546. /* {{{ proto array apache_request_err_headers_out([{string name|array list} [, string value [, bool replace = false]]])
  547. * fetch all headers that go out in case of an error or a subrequest
  548. */
  549. PHP_FUNCTION(apache_request_err_headers_out)
  550. {
  551. zval *id;
  552. request_rec *r;
  553. APREQ_GET_REQUEST(id, r);
  554. if (ZEND_NUM_ARGS() > 0)
  555. add_header_to_table(r->err_headers_out, INTERNAL_FUNCTION_PARAM_PASSTHRU);
  556. apache_table_to_zval(r->err_headers_out, 0, return_value);
  557. }
  558. /* }}} */
  559. /* {{{ proxy functions for the ap_* functions family
  560. */
  561. /* {{{ proto int apache_request_server_port()
  562. */
  563. PHP_FUNCTION(apache_request_server_port)
  564. {
  565. zval *id;
  566. request_rec *r;
  567. if (ZEND_NUM_ARGS() > 0) {
  568. WRONG_PARAM_COUNT;
  569. }
  570. APREQ_GET_REQUEST(id, r);
  571. RETURN_LONG(ap_get_server_port(r));
  572. }
  573. /* }}} */
  574. /* {{{ proto int apache_request_remote_host([int type])
  575. */
  576. PHP_FUNCTION(apache_request_remote_host)
  577. {
  578. zval *id, **ztype;
  579. request_rec *r;
  580. char *res;
  581. int type = REMOTE_NAME;
  582. switch (ZEND_NUM_ARGS()) {
  583. case 0:
  584. break;
  585. case 1:
  586. if (zend_get_parameters_ex(1, &ztype) == FAILURE) {
  587. RETURN_FALSE;
  588. }
  589. convert_to_long_ex(ztype);
  590. type = Z_LVAL_PP(ztype);
  591. break;
  592. default:
  593. WRONG_PARAM_COUNT;
  594. break;
  595. }
  596. APREQ_GET_REQUEST(id, r);
  597. res = (char *)ap_get_remote_host(r->connection, r->per_dir_config, type);
  598. if (res)
  599. RETURN_STRING(res, 1);
  600. RETURN_EMPTY_STRING();
  601. }
  602. /* }}} */
  603. /* {{{ proto long apache_request_update_mtime([int dependency_mtime])
  604. */
  605. PHP_FUNCTION(apache_request_update_mtime)
  606. {
  607. zval *id, **zmtime;
  608. request_rec *r;
  609. int mtime = 0;
  610. switch (ZEND_NUM_ARGS()) {
  611. case 0:
  612. break;
  613. case 1:
  614. if (zend_get_parameters_ex(1, &zmtime) == FAILURE) {
  615. RETURN_FALSE;
  616. }
  617. convert_to_long_ex(zmtime);
  618. mtime = Z_LVAL_PP(zmtime);
  619. break;
  620. default:
  621. WRONG_PARAM_COUNT;
  622. break;
  623. }
  624. APREQ_GET_REQUEST(id, r);
  625. RETURN_LONG(ap_update_mtime(r, mtime));
  626. }
  627. /* }}} */
  628. /* {{{ proto void apache_request_set_etag()
  629. */
  630. PHP_FUNCTION(apache_request_set_etag)
  631. {
  632. zval *id;
  633. request_rec *r;
  634. if (ZEND_NUM_ARGS() > 0) {
  635. WRONG_PARAM_COUNT;
  636. }
  637. APREQ_GET_REQUEST(id, r);
  638. ap_set_etag(r);
  639. RETURN_TRUE;
  640. }
  641. /* }}} */
  642. /* {{{ proto void apache_request_set_last_modified()
  643. */
  644. PHP_FUNCTION(apache_request_set_last_modified)
  645. {
  646. zval *id;
  647. request_rec *r;
  648. if (ZEND_NUM_ARGS() > 0) {
  649. WRONG_PARAM_COUNT;
  650. }
  651. APREQ_GET_REQUEST(id, r);
  652. ap_set_last_modified(r);
  653. RETURN_TRUE;
  654. }
  655. /* }}} */
  656. /* {{{ proto long apache_request_meets_conditions()
  657. */
  658. PHP_FUNCTION(apache_request_meets_conditions)
  659. {
  660. zval *id;
  661. request_rec *r;
  662. if (ZEND_NUM_ARGS() > 0) {
  663. WRONG_PARAM_COUNT;
  664. }
  665. APREQ_GET_REQUEST(id, r);
  666. RETURN_LONG(ap_meets_conditions(r));
  667. }
  668. /* }}} */
  669. /* {{{ proto long apache_request_discard_request_body()
  670. */
  671. PHP_FUNCTION(apache_request_discard_request_body)
  672. {
  673. zval *id;
  674. request_rec *r;
  675. if (ZEND_NUM_ARGS() > 0) {
  676. WRONG_PARAM_COUNT;
  677. }
  678. APREQ_GET_REQUEST(id, r);
  679. RETURN_LONG(ap_discard_request_body(r));
  680. }
  681. /* }}} */
  682. /* {{{ proto long apache_request_satisfies()
  683. */
  684. PHP_FUNCTION(apache_request_satisfies)
  685. {
  686. zval *id;
  687. request_rec *r;
  688. if (ZEND_NUM_ARGS() > 0) {
  689. WRONG_PARAM_COUNT;
  690. }
  691. APREQ_GET_REQUEST(id, r);
  692. RETURN_LONG(ap_satisfies(r));
  693. }
  694. /* }}} */
  695. /* {{{ proto bool apache_request_is_initial_req()
  696. */
  697. PHP_FUNCTION(apache_request_is_initial_req)
  698. {
  699. zval *id;
  700. request_rec *r;
  701. if (ZEND_NUM_ARGS() > 0) {
  702. WRONG_PARAM_COUNT;
  703. }
  704. APREQ_GET_REQUEST(id, r);
  705. RETURN_BOOL(ap_is_initial_req(r));
  706. }
  707. /* }}} */
  708. /* {{{ proto bool apache_request_some_auth_required()
  709. */
  710. PHP_FUNCTION(apache_request_some_auth_required)
  711. {
  712. zval *id;
  713. request_rec *r;
  714. if (ZEND_NUM_ARGS() > 0) {
  715. WRONG_PARAM_COUNT;
  716. }
  717. APREQ_GET_REQUEST(id, r);
  718. RETURN_BOOL(ap_some_auth_required(r));
  719. }
  720. /* }}} */
  721. /* {{{ proto string apache_request_auth_type()
  722. */
  723. PHP_FUNCTION(apache_request_auth_type)
  724. {
  725. zval *id;
  726. request_rec *r;
  727. char *t;
  728. if (ZEND_NUM_ARGS() > 0) {
  729. WRONG_PARAM_COUNT;
  730. }
  731. APREQ_GET_REQUEST(id, r);
  732. t = (char *)ap_auth_type(r);
  733. if (!t)
  734. RETURN_NULL();
  735. RETURN_STRING(t, 1);
  736. }
  737. /* }}} */
  738. /* {{{ proto string apache_request_auth_name()
  739. */
  740. PHP_FUNCTION(apache_request_auth_name)
  741. {
  742. zval *id;
  743. request_rec *r;
  744. char *t;
  745. if (ZEND_NUM_ARGS() > 0) {
  746. WRONG_PARAM_COUNT;
  747. }
  748. APREQ_GET_REQUEST(id, r);
  749. t = (char *)ap_auth_name(r);
  750. if (!t)
  751. RETURN_NULL();
  752. RETURN_STRING(t, 1);
  753. }
  754. /* }}} */
  755. /* {{{ proto apache_request_basic_auth_pw()
  756. */
  757. PHP_FUNCTION(apache_request_basic_auth_pw)
  758. {
  759. zval *id, *zpw;
  760. request_rec *r;
  761. const char *pw;
  762. long status;
  763. if (ZEND_NUM_ARGS() != 1) {
  764. WRONG_PARAM_COUNT;
  765. }
  766. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zpw) == FAILURE) {
  767. RETURN_NULL();
  768. }
  769. if (!PZVAL_IS_REF(zpw)) {
  770. zend_error(E_WARNING, "Parameter wasn't passed by reference");
  771. RETURN_NULL();
  772. }
  773. APREQ_GET_REQUEST(id, r);
  774. pw = NULL;
  775. status = ap_get_basic_auth_pw(r, &pw);
  776. if (status == OK && pw) {
  777. ZVAL_STRING(zpw, (char *)pw, 1);
  778. }
  779. else
  780. ZVAL_NULL(zpw);
  781. RETURN_LONG(status);
  782. }
  783. /* }}} */
  784. /* http_protocol.h */
  785. PHP_FUNCTION(apache_request_send_http_header)
  786. {
  787. zval *id;
  788. request_rec *r;
  789. char *type = NULL;
  790. int typelen;
  791. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &type, &typelen) == FAILURE)
  792. return;
  793. APREQ_GET_REQUEST(id, r);
  794. if(type) {
  795. r->content_type = pstrdup(r->pool, type);
  796. }
  797. ap_send_http_header(r);
  798. SG(headers_sent) = 1;
  799. AP(headers_sent) = 1;
  800. RETURN_TRUE;
  801. }
  802. PHP_FUNCTION(apache_request_basic_http_header)
  803. {
  804. zval *id;
  805. request_rec *r;
  806. APREQ_GET_REQUEST(id, r);
  807. ap_basic_http_header((request_rec *)SG(server_context));
  808. SG(headers_sent) = 1;
  809. AP(headers_sent) = 1;
  810. RETURN_TRUE;
  811. }
  812. PHP_FUNCTION(apache_request_send_http_trace)
  813. {
  814. zval *id;
  815. request_rec *r;
  816. APREQ_GET_REQUEST(id, r);
  817. ap_send_http_trace((request_rec *)SG(server_context));
  818. SG(headers_sent) = 1;
  819. AP(headers_sent) = 1;
  820. RETURN_TRUE;
  821. }
  822. PHP_FUNCTION(apache_request_send_http_options)
  823. {
  824. zval *id;
  825. request_rec *r;
  826. APREQ_GET_REQUEST(id, r);
  827. ap_send_http_options((request_rec *)SG(server_context));
  828. SG(headers_sent) = 1;
  829. AP(headers_sent) = 1;
  830. RETURN_TRUE;
  831. }
  832. PHP_FUNCTION(apache_request_send_error_response)
  833. {
  834. zval **recursive;
  835. zval *id;
  836. request_rec *r;
  837. int rec;
  838. switch(ZEND_NUM_ARGS()) {
  839. case 0:
  840. rec = 0;
  841. break;
  842. case 1:
  843. if(zend_get_parameters_ex(1, &recursive) == FAILURE) {
  844. RETURN_FALSE;
  845. }
  846. convert_to_long_ex(recursive);
  847. rec = Z_LVAL_PP(recursive);
  848. break;
  849. default:
  850. WRONG_PARAM_COUNT;
  851. }
  852. APREQ_GET_REQUEST(id, r);
  853. ap_send_error_response(r, rec);
  854. RETURN_TRUE;
  855. }
  856. PHP_FUNCTION(apache_request_set_content_length)
  857. {
  858. zval **length;
  859. zval *id;
  860. request_rec *r;
  861. if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &length) == FAILURE) {
  862. WRONG_PARAM_COUNT;
  863. }
  864. APREQ_GET_REQUEST(id, r);
  865. convert_to_long_ex(length);
  866. ap_set_content_length(r, Z_LVAL_PP(length));
  867. RETURN_TRUE;
  868. }
  869. PHP_FUNCTION(apache_request_set_keepalive)
  870. {
  871. zval *id;
  872. request_rec *r;
  873. APREQ_GET_REQUEST(id, r);
  874. ap_set_keepalive(r);
  875. RETURN_TRUE;
  876. }
  877. /* This stuff should use streams or however this is implemented now
  878. PHP_FUNCTION(apache_request_send_fd)
  879. {
  880. }
  881. PHP_FUNCTION(apache_request_send_fd_length)
  882. {
  883. }
  884. */
  885. /* These are for overriding default output behaviour */
  886. PHP_FUNCTION(apache_request_rputs)
  887. {
  888. zval **buffer;
  889. zval *id;
  890. request_rec *r;
  891. if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &buffer) == FAILURE) {
  892. WRONG_PARAM_COUNT;
  893. }
  894. APREQ_GET_REQUEST(id, r);
  895. convert_to_string_ex(buffer);
  896. ap_rwrite(Z_STRVAL_PP(buffer), Z_STRLEN_PP(buffer), (request_rec*)SG(server_context));
  897. }
  898. /* This stuff would be useful for custom POST handlers,
  899. which should be supported. Probably by not using
  900. sapi_activate at all inside a phpResponseHandler
  901. and instead using a builtin composed of the below
  902. calls as a apache_read_request_body() and allow
  903. people to custom craft their own.
  904. PHP_FUNCTION(apache_request_setup_client_block)
  905. {
  906. }
  907. PHP_FUNCTION(apache_request_should_client_block)
  908. {
  909. }
  910. PHP_FUNCTION(apache_request_get_client_block)
  911. {
  912. }
  913. PHP_FUNCTION(apache_request_discard_request_body)
  914. {
  915. }
  916. */
  917. /* http_log.h */
  918. /* {{{ proto boolean apache_request_log_error(string message, [long facility])
  919. */
  920. PHP_FUNCTION(apache_request_log_error)
  921. {
  922. zval *id;
  923. zval **z_errstr, **z_facility;
  924. request_rec *r;
  925. int facility = APLOG_ERR;
  926. switch(ZEND_NUM_ARGS()) {
  927. case 1:
  928. if(zend_get_parameters_ex(1, &z_errstr) == FAILURE) {
  929. RETURN_FALSE;
  930. }
  931. break;
  932. case 2:
  933. if(zend_get_parameters_ex(1, &z_errstr, &z_facility) == FAILURE) {
  934. RETURN_FALSE;
  935. }
  936. convert_to_long_ex(z_facility);
  937. facility = Z_LVAL_PP(z_facility);
  938. break;
  939. default:
  940. WRONG_PARAM_COUNT;
  941. break;
  942. }
  943. APREQ_GET_REQUEST(id, r);
  944. convert_to_string_ex(z_errstr);
  945. ap_log_error(APLOG_MARK, facility, r->server, "%s", Z_STRVAL_PP(z_errstr));
  946. RETURN_TRUE;
  947. }
  948. /* }}} */
  949. /* http_main.h */
  950. /* {{{ proto object apache_request_sub_req_lookup_uri(string uri)
  951. Returns sub-request for the specified uri. You would
  952. need to run it yourself with run()
  953. */
  954. PHP_FUNCTION(apache_request_sub_req_lookup_uri)
  955. {
  956. zval *id;
  957. zval **file;
  958. request_rec *r, *sub_r;
  959. if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &file) == FAILURE) {
  960. WRONG_PARAM_COUNT;
  961. }
  962. APREQ_GET_REQUEST(id, r);
  963. convert_to_string_ex(file);
  964. sub_r = ap_sub_req_lookup_uri(Z_STRVAL_PP(file), r);
  965. if(!sub_r) {
  966. RETURN_FALSE;
  967. }
  968. return_value = php_apache_request_new(sub_r);
  969. }
  970. /* }}} */
  971. /* {{{ proto object apache_request_sub_req_lookup_file(string file)
  972. Returns sub-request for the specified file. You would
  973. need to run it yourself with run().
  974. */
  975. PHP_FUNCTION(apache_request_sub_req_lookup_file)
  976. {
  977. zval *id;
  978. zval **file;
  979. request_rec *r, *sub_r;
  980. if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &file) == FAILURE) {
  981. WRONG_PARAM_COUNT;
  982. }
  983. APREQ_GET_REQUEST(id, r);
  984. convert_to_string_ex(file);
  985. sub_r = ap_sub_req_lookup_file(Z_STRVAL_PP(file), r);
  986. if(!sub_r) {
  987. RETURN_FALSE;
  988. }
  989. return_value = php_apache_request_new(sub_r);
  990. }
  991. /* }}} */
  992. /* {{{ proto object apache_request_sub_req_method_uri(string method, string uri)
  993. Returns sub-request for the specified file. You would
  994. need to run it yourself with run().
  995. */
  996. PHP_FUNCTION(apache_request_sub_req_method_uri)
  997. {
  998. zval *id;
  999. zval **file, **method;
  1000. request_rec *r, *sub_r;
  1001. if(ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &method, &file) == FAILURE) {
  1002. WRONG_PARAM_COUNT;
  1003. }
  1004. APREQ_GET_REQUEST(id, r);
  1005. convert_to_string_ex(method);
  1006. convert_to_string_ex(file);
  1007. sub_r = ap_sub_req_method_uri(Z_STRVAL_PP(method),Z_STRVAL_PP(file), r);
  1008. if(!sub_r) {
  1009. RETURN_FALSE;
  1010. }
  1011. return_value = php_apache_request_new(sub_r);
  1012. }
  1013. /* }}} */
  1014. /* {{{ proto long apache_request_run
  1015. This is a wrapper for ap_sub_run_req and ap_destory_sub_req. It takes
  1016. sub_request, runs it, destroys it, and returns it's status.
  1017. */
  1018. PHP_FUNCTION(apache_request_run)
  1019. {
  1020. zval *id;
  1021. request_rec *r;
  1022. int status;
  1023. APREQ_GET_REQUEST(id, r);
  1024. if(!r || ap_is_initial_req(r))
  1025. RETURN_FALSE;
  1026. status = ap_run_sub_req(r);
  1027. ap_destroy_sub_req(r);
  1028. RETURN_LONG(status);
  1029. }
  1030. /* }}} */
  1031. PHP_FUNCTION(apache_request_internal_redirect)
  1032. {
  1033. zval *id;
  1034. zval **new_uri;
  1035. request_rec *r;
  1036. if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &new_uri) == FAILURE) {
  1037. WRONG_PARAM_COUNT;
  1038. }
  1039. APREQ_GET_REQUEST(id, r);
  1040. convert_to_string_ex(new_uri);
  1041. ap_internal_redirect(Z_STRVAL_PP(new_uri), r);
  1042. }
  1043. PHP_FUNCTION(apache_request_send_header_field)
  1044. {
  1045. zval **fieldname;
  1046. zval **fieldval;
  1047. zval *id;
  1048. request_rec *r;
  1049. if(ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &fieldname, &fieldval) == FAILURE) {
  1050. WRONG_PARAM_COUNT;
  1051. }
  1052. convert_to_string_ex(fieldname);
  1053. convert_to_string_ex(fieldval);
  1054. APREQ_GET_REQUEST(id, r);
  1055. ap_send_header_field(r, Z_STRVAL_PP(fieldname), Z_STRVAL_PP(fieldval));
  1056. SG(headers_sent) = 1;
  1057. AP(headers_sent) = 1;
  1058. }
  1059. /* }}} */
  1060. /* {{{ php_apache_request_class_functions
  1061. */
  1062. static function_entry php_apache_request_class_functions[] = {
  1063. /* string slots */
  1064. PHP_FALIAS(args, apache_request_args, NULL)
  1065. PHP_FALIAS(boundary, apache_request_boundary, NULL)
  1066. PHP_FALIAS(content_encoding, apache_request_content_encoding, NULL)
  1067. PHP_FALIAS(content_type, apache_request_content_type, NULL)
  1068. PHP_FALIAS(filename, apache_request_filename, NULL)
  1069. PHP_FALIAS(handler, apache_request_handler, NULL)
  1070. PHP_FALIAS(hostname, apache_request_hostname, NULL)
  1071. PHP_FALIAS(method, apache_request_method, NULL)
  1072. PHP_FALIAS(path_info, apache_request_path_info, NULL)
  1073. PHP_FALIAS(protocol, apache_request_protocol, NULL)
  1074. PHP_FALIAS(status_line, apache_request_status_line, NULL)
  1075. PHP_FALIAS(the_request, apache_request_the_request, NULL)
  1076. PHP_FALIAS(unparsed_uri, apache_request_unparsed_uri, NULL)
  1077. PHP_FALIAS(uri, apache_request_uri, NULL)
  1078. /* int slots */
  1079. PHP_FALIAS(allowed, apache_request_allowed, NULL)
  1080. PHP_FALIAS(bytes_sent, apache_request_bytes_sent, NULL)
  1081. PHP_FALIAS(chunked, apache_request_chunked, NULL)
  1082. PHP_FALIAS(content_length, apache_request_content_length, NULL)
  1083. PHP_FALIAS(header_only, apache_request_header_only, NULL)
  1084. PHP_FALIAS(method_number, apache_request_method_number, NULL)
  1085. PHP_FALIAS(mtime, apache_request_mtime, NULL)
  1086. PHP_FALIAS(no_cache, apache_request_no_cache, NULL)
  1087. PHP_FALIAS(no_local_copy, apache_request_no_local_copy, NULL)
  1088. PHP_FALIAS(proto_num, apache_request_proto_num, NULL)
  1089. PHP_FALIAS(proxyreq, apache_request_proxyreq, NULL)
  1090. PHP_FALIAS(read_body, apache_request_read_body, NULL)
  1091. PHP_FALIAS(remaining, apache_request_remaining, NULL)
  1092. PHP_FALIAS(request_time, apache_request_request_time, NULL)
  1093. PHP_FALIAS(status, apache_request_status, NULL)
  1094. /* tables & arrays */
  1095. PHP_FALIAS(headers_in, apache_request_headers_in, NULL)
  1096. PHP_FALIAS(headers_out, apache_request_headers_out, NULL)
  1097. PHP_FALIAS(err_headers_out, apache_request_err_headers_out, NULL)
  1098. /* proxy functions for the ap_* functions family */
  1099. #undef auth_name
  1100. #undef auth_type
  1101. #undef discard_request_body
  1102. #undef is_initial_req
  1103. #undef meets_conditions
  1104. #undef satisfies
  1105. #undef set_etag
  1106. #undef set_last_modified
  1107. #undef some_auth_required
  1108. #undef update_mtime
  1109. #undef send_http_header
  1110. #undef send_header_field
  1111. #undef basic_http_header
  1112. #undef send_http_trace
  1113. #undef send_http_options
  1114. #undef send_error_response
  1115. #undef set_content_length
  1116. #undef set_keepalive
  1117. #undef rputs
  1118. #undef log_error
  1119. #undef lookup_uri
  1120. #undef lookup_file
  1121. #undef method_uri
  1122. #undef run
  1123. #undef internal_redirect
  1124. PHP_FALIAS(auth_name, apache_request_auth_name, NULL)
  1125. PHP_FALIAS(auth_type, apache_request_auth_type, NULL)
  1126. PHP_FALIAS(basic_auth_pw, apache_request_basic_auth_pw, NULL)
  1127. PHP_FALIAS(discard_request_body, apache_request_discard_request_body, NULL)
  1128. PHP_FALIAS(is_initial_req, apache_request_is_initial_req, NULL)
  1129. PHP_FALIAS(meets_conditions, apache_request_meets_conditions, NULL)
  1130. PHP_FALIAS(remote_host, apache_request_remote_host, NULL)
  1131. PHP_FALIAS(satisfies, apache_request_satisfies, NULL)
  1132. PHP_FALIAS(server_port, apache_request_server_port, NULL)
  1133. PHP_FALIAS(set_etag, apache_request_set_etag, NULL)
  1134. PHP_FALIAS(set_last_modified, apache_request_set_last_modified, NULL)
  1135. PHP_FALIAS(some_auth_required, apache_request_some_auth_required, NULL)
  1136. PHP_FALIAS(update_mtime, apache_request_update_mtime, NULL)
  1137. PHP_FALIAS(send_http_header, apache_request_send_http_header, NULL)
  1138. PHP_FALIAS(basic_http_header, apache_request_basic_http_header, NULL)
  1139. PHP_FALIAS(send_header_field, apache_request_send_header_field, NULL)
  1140. PHP_FALIAS(send_http_trace, apache_request_send_http_trace, NULL)
  1141. PHP_FALIAS(send_http_options, apache_request_send_http_trace, NULL)
  1142. PHP_FALIAS(send_error_response, apache_request_send_error_response, NULL)
  1143. PHP_FALIAS(set_content_length, apache_request_set_content_length, NULL)
  1144. PHP_FALIAS(set_keepalive, apache_request_set_keepalive, NULL)
  1145. PHP_FALIAS(rputs, apache_request_rputs, NULL)
  1146. PHP_FALIAS(log_error, apache_request_log_error, NULL)
  1147. PHP_FALIAS(lookup_uri, apache_request_sub_req_lookup_uri, NULL)
  1148. PHP_FALIAS(lookup_file, apache_request_sub_req_lookup_file, NULL)
  1149. PHP_FALIAS(method_uri, apache_request_sub_req_method_uri, NULL)
  1150. PHP_FALIAS(run, apache_request_run, NULL)
  1151. PHP_FALIAS(internal_redirect, apache_request_internal_redirect, NULL)
  1152. { NULL, NULL, NULL }
  1153. };
  1154. /* }}} */
  1155. static PHP_MINIT_FUNCTION(apache)
  1156. {
  1157. zend_class_entry ce;
  1158. #ifdef ZTS
  1159. ts_allocate_id(&php_apache_info_id, sizeof(php_apache_info_struct), (ts_allocate_ctor) php_apache_globals_ctor, NULL);
  1160. #else
  1161. php_apache_globals_ctor(&php_apache_info TSRMLS_CC);
  1162. #endif
  1163. REGISTER_INI_ENTRIES();
  1164. le_apachereq = zend_register_list_destructors_ex(php_apache_request_free, NULL, "ApacheRequest", module_number);
  1165. INIT_OVERLOADED_CLASS_ENTRY(ce, "ApacheRequest", php_apache_request_class_functions, NULL, NULL, NULL);
  1166. apacherequest_class_entry = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC);
  1167. REGISTER_LONG_CONSTANT("OK", OK, CONST_CS | CONST_PERSISTENT);
  1168. REGISTER_LONG_CONSTANT("DECLINED", DECLINED, CONST_CS | CONST_PERSISTENT);
  1169. REGISTER_LONG_CONSTANT("FORBIDDEN", FORBIDDEN, CONST_CS | CONST_PERSISTENT);
  1170. REGISTER_LONG_CONSTANT("AUTH_REQUIRED", AUTH_REQUIRED, CONST_CS | CONST_PERSISTENT);
  1171. REGISTER_LONG_CONSTANT("DONE", DONE, CONST_CS | CONST_PERSISTENT);
  1172. REGISTER_LONG_CONSTANT("SERVER_ERROR", SERVER_ERROR, CONST_CS | CONST_PERSISTENT);
  1173. REGISTER_LONG_CONSTANT("REDIRECT", REDIRECT, CONST_CS | CONST_PERSISTENT);
  1174. REGISTER_LONG_CONSTANT("BAD_REQUEST", BAD_REQUEST, CONST_CS | CONST_PERSISTENT);
  1175. REGISTER_LONG_CONSTANT("NOT_FOUND", NOT_FOUND, CONST_CS | CONST_PERSISTENT);
  1176. REGISTER_LONG_CONSTANT("HTTP_CONTINUE", HTTP_CONTINUE, CONST_CS | CONST_PERSISTENT);
  1177. REGISTER_LONG_CONSTANT("HTTP_SWITCHING_PROTOCOLS", HTTP_SWITCHING_PROTOCOLS, CONST_CS | CONST_PERSISTENT);
  1178. REGISTER_LONG_CONSTANT("HTTP_PROCESSING", HTTP_PROCESSING, CONST_CS | CONST_PERSISTENT);
  1179. REGISTER_LONG_CONSTANT("HTTP_OK", HTTP_OK, CONST_CS | CONST_PERSISTENT);
  1180. REGISTER_LONG_CONSTANT("HTTP_CREATED", HTTP_CREATED, CONST_CS | CONST_PERSISTENT);
  1181. REGISTER_LONG_CONSTANT("HTTP_ACCEPTED", HTTP_ACCEPTED, CONST_CS | CONST_PERSISTENT);
  1182. REGISTER_LONG_CONSTANT("HTTP_NON_AUTHORITATIVE", HTTP_NON_AUTHORITATIVE, CONST_CS | CONST_PERSISTENT);
  1183. REGISTER_LONG_CONSTANT("HTTP_NO_CONTENT", HTTP_NO_CONTENT, CONST_CS | CONST_PERSISTENT);
  1184. REGISTER_LONG_CONSTANT("HTTP_RESET_CONTENT", HTTP_RESET_CONTENT, CONST_CS | CONST_PERSISTENT);
  1185. REGISTER_LONG_CONSTANT("HTTP_PARTIAL_CONTENT", HTTP_PARTIAL_CONTENT, CONST_CS | CONST_PERSISTENT);
  1186. REGISTER_LONG_CONSTANT("HTTP_MULTI_STATUS", HTTP_MULTI_STATUS, CONST_CS | CONST_PERSISTENT);
  1187. REGISTER_LONG_CONSTANT("HTTP_MULTIPLE_CHOICES", HTTP_MULTIPLE_CHOICES, CONST_CS | CONST_PERSISTENT);
  1188. REGISTER_LONG_CONSTANT("HTTP_MOVED_PERMANENTLY", HTTP_MOVED_PERMANENTLY, CONST_CS | CONST_PERSISTENT);
  1189. REGISTER_LONG_CONSTANT("HTTP_MOVED_TEMPORARILY", HTTP_MOVED_TEMPORARILY, CONST_CS | CONST_PERSISTENT);
  1190. REGISTER_LONG_CONSTANT("HTTP_SEE_OTHER", HTTP_SEE_OTHER, CONST_CS | CONST_PERSISTENT);
  1191. REGISTER_LONG_CONSTANT("HTTP_NOT_MODIFIED", HTTP_NOT_MODIFIED, CONST_CS | CONST_PERSISTENT);
  1192. REGISTER_LONG_CONSTANT("HTTP_USE_PROXY", HTTP_USE_PROXY, CONST_CS | CONST_PERSISTENT);
  1193. REGISTER_LONG_CONSTANT("HTTP_TEMPORARY_REDIRECT", HTTP_TEMPORARY_REDIRECT, CONST_CS | CONST_PERSISTENT);
  1194. REGISTER_LONG_CONSTANT("HTTP_BAD_REQUEST", HTTP_BAD_REQUEST, CONST_CS | CONST_PERSISTENT);
  1195. REGISTER_LONG_CONSTANT("HTTP_UNAUTHORIZED", HTTP_UNAUTHORIZED, CONST_CS | CONST_PERSISTENT);
  1196. REGISTER_LONG_CONSTANT("HTTP_PAYMENT_REQUIRED", HTTP_PAYMENT_REQUIRED, CONST_CS | CONST_PERSISTENT);
  1197. REGISTER_LONG_CONSTANT("HTTP_FORBIDDEN", HTTP_FORBIDDEN, CONST_CS | CONST_PERSISTENT);
  1198. REGISTER_LONG_CONSTANT("HTTP_NOT_FOUND", HTTP_NOT_FOUND, CONST_CS | CONST_PERSISTENT);
  1199. REGISTER_LONG_CONSTANT("HTTP_METHOD_NOT_ALLOWED", HTTP_METHOD_NOT_ALLOWED, CONST_CS | CONST_PERSISTENT);
  1200. REGISTER_LONG_CONSTANT("HTTP_NOT_ACCEPTABLE", HTTP_NOT_ACCEPTABLE, CONST_CS | CONST_PERSISTENT);
  1201. REGISTER_LONG_CONSTANT("HTTP_PROXY_AUTHENTICATION_REQUIRED", HTTP_PROXY_AUTHENTICATION_REQUIRED, CONST_CS | CONST_PERSISTENT);
  1202. REGISTER_LONG_CONSTANT("HTTP_REQUEST_TIME_OUT", HTTP_REQUEST_TIME_OUT, CONST_CS | CONST_PERSISTENT);
  1203. REGISTER_LONG_CONSTANT("HTTP_CONFLICT", HTTP_CONFLICT, CONST_CS | CONST_PERSISTENT);
  1204. REGISTER_LONG_CONSTANT("HTTP_GONE", HTTP_GONE, CONST_CS | CONST_PERSISTENT);REGISTER_LONG_CONSTANT("HTTP_LENGTH_REQUIRED", HTTP_LENGTH_REQUIRED, CONST_CS | CONST_PERSISTENT);
  1205. REGISTER_LONG_CONSTANT("HTTP_PRECONDITION_FAILED", HTTP_PRECONDITION_FAILED, CONST_CS | CONST_PERSISTENT);
  1206. REGISTER_LONG_CONSTANT("HTTP_REQUEST_ENTITY_TOO_LARGE", HTTP_REQUEST_ENTITY_TOO_LARGE, CONST_CS | CONST_PERSISTENT);
  1207. REGISTER_LONG_CONSTANT("HTTP_REQUEST_URI_TOO_LARGE", HTTP_REQUEST_URI_TOO_LARGE, CONST_CS | CONST_PERSISTENT);
  1208. REGISTER_LONG_CONSTANT("HTTP_UNSUPPORTED_MEDIA_TYPE", HTTP_UNSUPPORTED_MEDIA_TYPE, CONST_CS | CONST_PERSISTENT);
  1209. REGISTER_LONG_CONSTANT("HTTP_RANGE_NOT_SATISFIABLE", HTTP_RANGE_NOT_SATISFIABLE, CONST_CS | CONST_PERSISTENT);
  1210. REGISTER_LONG_CONSTANT("HTTP_EXPECTATION_FAILED", HTTP_EXPECTATION_FAILED, CONST_CS | CONST_PERSISTENT);
  1211. REGISTER_LONG_CONSTANT("HTTP_UNPROCESSABLE_ENTITY", HTTP_UNPROCESSABLE_ENTITY, CONST_CS | CONST_PERSISTENT);
  1212. REGISTER_LONG_CONSTANT("HTTP_LOCKED", HTTP_LOCKED, CONST_CS | CONST_PERSISTENT);
  1213. REGISTER_LONG_CONSTANT("HTTP_FAILED_DEPENDENCY", HTTP_FAILED_DEPENDENCY, CONST_CS | CONST_PERSISTENT);
  1214. REGISTER_LONG_CONSTANT("HTTP_INTERNAL_SERVER_ERROR", HTTP_INTERNAL_SERVER_ERROR, CONST_CS | CONST_PERSISTENT);
  1215. REGISTER_LONG_CONSTANT("HTTP_NOT_IMPLEMENTED", HTTP_NOT_IMPLEMENTED, CONST_CS | CONST_PERSISTENT);
  1216. REGISTER_LONG_CONSTANT("HTTP_BAD_GATEWAY", HTTP_BAD_GATEWAY, CONST_CS | CONST_PERSISTENT);
  1217. REGISTER_LONG_CONSTANT("HTTP_SERVICE_UNAVAILABLE", HTTP_SERVICE_UNAVAILABLE, CONST_CS | CONST_PERSISTENT);
  1218. REGISTER_LONG_CONSTANT("HTTP_GATEWAY_TIME_OUT", HTTP_GATEWAY_TIME_OUT, CONST_CS | CONST_PERSISTENT);
  1219. REGISTER_LONG_CONSTANT("HTTP_VERSION_NOT_SUPPORTED", HTTP_VERSION_NOT_SUPPORTED, CONST_CS | CONST_PERSISTENT);
  1220. REGISTER_LONG_CONSTANT("HTTP_VARIANT_ALSO_VARIES", HTTP_VARIANT_ALSO_VARIES, CONST_CS | CONST_PERSISTENT);
  1221. REGISTER_LONG_CONSTANT("HTTP_INSUFFICIENT_STORAGE", HTTP_INSUFFICIENT_STORAGE, CONST_CS | CONST_PERSISTENT);
  1222. REGISTER_LONG_CONSTANT("HTTP_NOT_EXTENDED", HTTP_NOT_EXTENDED, CONST_CS | CONST_PERSISTENT);
  1223. REGISTER_LONG_CONSTANT("APLOG_EMERG", APLOG_EMERG, CONST_CS | CONST_PERSISTENT);
  1224. REGISTER_LONG_CONSTANT("APLOG_ALERT", APLOG_ALERT, CONST_CS | CONST_PERSISTENT);
  1225. REGISTER_LONG_CONSTANT("APLOG_CRIT", APLOG_CRIT, CONST_CS | CONST_PERSISTENT);
  1226. REGISTER_LONG_CONSTANT("APLOG_ERR", APLOG_ERR, CONST_CS | CONST_PERSISTENT);
  1227. REGISTER_LONG_CONSTANT("APLOG_WARNING", APLOG_WARNING, CONST_CS | CONST_PERSISTENT);
  1228. REGISTER_LONG_CONSTANT("APLOG_NOTICE", APLOG_NOTICE, CONST_CS | CONST_PERSISTENT);
  1229. REGISTER_LONG_CONSTANT("APLOG_INFO", APLOG_INFO, CONST_CS | CONST_PERSISTENT);
  1230. REGISTER_LONG_CONSTANT("APLOG_DEBUG", APLOG_DEBUG, CONST_CS | CONST_PERSISTENT);
  1231. REGISTER_LONG_CONSTANT("M_GET", M_GET, CONST_CS | CONST_PERSISTENT);
  1232. REGISTER_LONG_CONSTANT("M_PUT", M_PUT, CONST_CS | CONST_PERSISTENT);
  1233. REGISTER_LONG_CONSTANT("M_POST", M_POST, CONST_CS | CONST_PERSISTENT);
  1234. REGISTER_LONG_CONSTANT("M_DELETE", M_DELETE, CONST_CS | CONST_PERSISTENT);
  1235. REGISTER_LONG_CONSTANT("M_CONNECT", M_CONNECT, CONST_CS | CONST_PERSISTENT);
  1236. REGISTER_LONG_CONSTANT("M_OPTIONS", M_OPTIONS, CONST_CS | CONST_PERSISTENT);
  1237. REGISTER_LONG_CONSTANT("M_TRACE", M_TRACE, CONST_CS | CONST_PERSISTENT);
  1238. REGISTER_LONG_CONSTANT("M_PATCH", M_PATCH, CONST_CS | CONST_PERSISTENT);
  1239. REGISTER_LONG_CONSTANT("M_PROPFIND", M_PROPFIND, CONST_CS | CONST_PERSISTENT);
  1240. REGISTER_LONG_CONSTANT("M_PROPPATCH", M_PROPPATCH, CONST_CS | CONST_PERSISTENT);
  1241. REGISTER_LONG_CONSTANT("M_MKCOL", M_MKCOL, CONST_CS | CONST_PERSISTENT);
  1242. REGISTER_LONG_CONSTANT("M_COPY", M_COPY, CONST_CS | CONST_PERSISTENT);
  1243. REGISTER_LONG_CONSTANT("M_MOVE", M_MOVE, CONST_CS | CONST_PERSISTENT);
  1244. REGISTER_LONG_CONSTANT("M_LOCK", M_LOCK, CONST_CS | CONST_PERSISTENT);
  1245. REGISTER_LONG_CONSTANT("M_UNLOCK", M_UNLOCK, CONST_CS | CONST_PERSISTENT);
  1246. REGISTER_LONG_CONSTANT("M_INVALID", M_INVALID, CONST_CS | CONST_PERSISTENT);
  1247. /* Possible values for request_rec.read_body (set by handling module):
  1248. * REQUEST_NO_BODY Send 413 error if message has any body
  1249. * REQUEST_CHUNKED_ERROR Send 411 error if body without Content-Length
  1250. * REQUEST_CHUNKED_DECHUNK If chunked, remove the chunks for me.
  1251. * REQUEST_CHUNKED_PASS Pass the chunks to me without removal.
  1252. */
  1253. REGISTER_LONG_CONSTANT("REQUEST_NO_BODY", REQUEST_NO_BODY, CONST_CS | CONST_PERSISTENT);
  1254. REGISTER_LONG_CONSTANT("REQUEST_CHUNKED_ERROR", REQUEST_CHUNKED_ERROR, CONST_CS | CONST_PERSISTENT);
  1255. REGISTER_LONG_CONSTANT("REQUEST_CHUNKED_DECHUNK", REQUEST_CHUNKED_DECHUNK, CONST_CS | CONST_PERSISTENT);
  1256. REGISTER_LONG_CONSTANT("REQUEST_CHUNKED_PASS", REQUEST_CHUNKED_PASS, CONST_CS | CONST_PERSISTENT);
  1257. /* resolve types for remote_host() */
  1258. REGISTER_LONG_CONSTANT("REMOTE_HOST", REMOTE_HOST, CONST_CS | CONST_PERSISTENT);
  1259. REGISTER_LONG_CONSTANT("REMOTE_NAME", REMOTE_NAME, CONST_CS | CONST_PERSISTENT);
  1260. REGISTER_LONG_CONSTANT("REMOTE_NOLOOKUP", REMOTE_NOLOOKUP, CONST_CS | CONST_PERSISTENT);
  1261. REGISTER_LONG_CONSTANT("REMOTE_DOUBLE_REV", REMOTE_DOUBLE_REV, CONST_CS | CONST_PERSISTENT);
  1262. return SUCCESS;
  1263. }
  1264. static PHP_MSHUTDOWN_FUNCTION(apache)
  1265. {
  1266. UNREGISTER_INI_ENTRIES();
  1267. return SUCCESS;
  1268. }
  1269. zend_module_entry apache_module_entry = {
  1270. STANDARD_MODULE_HEADER,
  1271. "apache",
  1272. apache_functions,
  1273. PHP_MINIT(apache),
  1274. PHP_MSHUTDOWN(apache),
  1275. NULL,
  1276. NULL,
  1277. PHP_MINFO(apache),
  1278. NO_VERSION_YET,
  1279. STANDARD_MODULE_PROPERTIES
  1280. };
  1281. /* {{{ proto bool apache_child_terminate(void)
  1282. Terminate apache process after this request */
  1283. PHP_FUNCTION(apache_child_terminate)
  1284. {
  1285. #ifndef MULTITHREAD
  1286. if (AP(terminate_child)) {
  1287. ap_child_terminate( ((request_rec *)SG(server_context)) );
  1288. RETURN_TRUE;
  1289. } else { /* tell them to get lost! */
  1290. php_error(E_WARNING, "apache.child_terminate is disabled");
  1291. RETURN_FALSE;
  1292. }
  1293. #else
  1294. php_error(E_WARNING, "apache_child_terminate() is not supported in this build");
  1295. RETURN_FALSE;
  1296. #endif
  1297. }
  1298. /* }}} */
  1299. /* {{{ proto string apache_note(string note_name [, string note_value])
  1300. Get and set Apache request notes */
  1301. PHP_FUNCTION(apache_note)
  1302. {
  1303. zval **arg_name, **arg_val;
  1304. char *note_val;
  1305. int arg_count = ZEND_NUM_ARGS();
  1306. if (arg_count<1 || arg_count>2 ||
  1307. zend_get_parameters_ex(arg_count, &arg_name, &arg_val) ==FAILURE ) {
  1308. WRONG_PARAM_COUNT;
  1309. }
  1310. convert_to_string_ex(arg_name);
  1311. note_val = (char *) table_get(((request_rec *)SG(server_context))->notes, (*arg_name)->value.str.val);
  1312. if (arg_count == 2) {
  1313. convert_to_string_ex(arg_val);
  1314. table_set(((request_rec *)SG(server_context))->notes, (*arg_name)->value.str.val, (*arg_val)->value.str.val);
  1315. }
  1316. if (note_val) {
  1317. RETURN_STRING(note_val, 1);
  1318. } else {
  1319. RETURN_FALSE;
  1320. }
  1321. }
  1322. /* }}} */
  1323. /* {{{ PHP_MINFO_FUNCTION
  1324. */
  1325. PHP_MINFO_FUNCTION(apache)
  1326. {
  1327. module *modp = NULL;
  1328. char output_buf[128];
  1329. #if !defined(WIN32) && !defined(WINNT)
  1330. char name[64];
  1331. char modulenames[1024];
  1332. char *p;
  1333. #endif
  1334. server_rec *serv;
  1335. extern char server_root[MAX_STRING_LEN];
  1336. extern uid_t user_id;
  1337. extern char *user_name;
  1338. extern gid_t group_id;
  1339. extern int max_requests_per_child;
  1340. serv = ((request_rec *) SG(server_context))->server;
  1341. php_info_print_table_start();
  1342. #ifdef PHP_WIN32
  1343. php_info_print_table_row(1, "Apache for Windows 95/NT");
  1344. php_info_print_table_end();
  1345. php_info_print_table_start();
  1346. #elif defined(NETWARE)
  1347. php_info_print_table_row(1, "Apache for NetWare");
  1348. php_info_print_table_end();
  1349. php_info_print_table_start();
  1350. #else
  1351. php_info_print_table_row(2, "APACHE_INCLUDE", PHP_APACHE_INCLUDE);
  1352. php_info_print_table_row(2, "APACHE_TARGET", PHP_APACHE_TARGET);
  1353. #endif
  1354. php_info_print_table_row(2, "Apache Version", SERVER_VERSION);
  1355. #ifdef APACHE_RELEASE
  1356. sprintf(output_buf, "%d", APACHE_RELEASE);
  1357. php_info_print_table_row(2, "Apache Release", output_buf);
  1358. #endif
  1359. sprintf(output_buf, "%d", MODULE_MAGIC_NUMBER);
  1360. php_info_print_table_row(2, "Apache API Version", output_buf);
  1361. sprintf(output_buf, "%s:%u", serv->server_hostname, serv->port);
  1362. php_info_print_table_row(2, "Hostname:Port", output_buf);
  1363. #if !defined(WIN32) && !defined(WINNT)
  1364. sprintf(output_buf, "%s(%d)/%d", user_name, (int)user_id, (int)group_id);
  1365. php_info_print_table_row(2, "User/Group", output_buf);
  1366. sprintf(output_buf, "Per Child: %d - Keep Alive: %s - Max Per Connection: %d", max_requests_per_child, serv->keep_alive ? "on":"off", serv->keep_alive_max);
  1367. php_info_print_table_row(2, "Max Requests", output_buf);
  1368. #endif
  1369. sprintf(output_buf, "Connection: %d - Keep-Alive: %d", serv->timeout, serv->keep_alive_timeout);
  1370. php_info_print_table_row(2, "Timeouts", output_buf);
  1371. #if !defined(WIN32) && !defined(WINNT)
  1372. /*
  1373. This block seems to be working on NetWare; But it seems to be showing
  1374. all modules instead of just the loaded ones
  1375. */
  1376. php_info_print_table_row(2, "Server Root", server_root);
  1377. strcpy(modulenames, "");
  1378. for(modp = top_module; modp; modp = modp->next) {
  1379. strlcpy(name, modp->name, sizeof(name));
  1380. if ((p = strrchr(name, '.'))) {
  1381. *p='\0'; /* Cut off ugly .c extensions on module names */
  1382. }
  1383. strcat(modulenames, name);
  1384. if (modp->next) {
  1385. strcat(modulenames, ", ");
  1386. }
  1387. }
  1388. php_info_print_table_row(2, "Loaded Modules", modulenames);
  1389. #endif
  1390. php_info_print_table_end();
  1391. DISPLAY_INI_ENTRIES();
  1392. {
  1393. register int i;
  1394. array_header *arr;
  1395. table_entry *elts;
  1396. request_rec *r;
  1397. r = ((request_rec *) SG(server_context));
  1398. arr = table_elts(r->subprocess_env);
  1399. elts = (table_entry *)arr->elts;
  1400. SECTION("Apache Environment");
  1401. php_info_print_table_start();
  1402. php_info_print_table_header(2, "Variable", "Value");
  1403. for (i=0; i < arr->nelts; i++) {
  1404. php_info_print_table_row(2, elts[i].key, elts[i].val);
  1405. }
  1406. php_info_print_table_end();
  1407. }
  1408. {
  1409. array_header *env_arr;
  1410. table_entry *env;
  1411. int i;
  1412. request_rec *r;
  1413. r = ((request_rec *) SG(server_context));
  1414. SECTION("HTTP Headers Information");
  1415. php_info_print_table_start();
  1416. php_info_print_table_colspan_header(2, "HTTP Request Headers");
  1417. php_info_print_table_row(2, "HTTP Request", r->the_request);
  1418. env_arr = table_elts(r->headers_in);
  1419. env = (table_entry *)env_arr->elts;
  1420. for (i = 0; i < env_arr->nelts; ++i) {
  1421. if (env[i].key && (!PG(safe_mode) || (PG(safe_mode) && strncasecmp(env[i].key, "authorization", 13)))) {
  1422. php_info_print_table_row(2, env[i].key, env[i].val);
  1423. }
  1424. }
  1425. php_info_print_table_colspan_header(2, "HTTP Response Headers");
  1426. env_arr = table_elts(r->headers_out);
  1427. env = (table_entry *)env_arr->elts;
  1428. for(i = 0; i < env_arr->nelts; ++i) {
  1429. if (env[i].key) {
  1430. php_info_print_table_row(2, env[i].key, env[i].val);
  1431. }
  1432. }
  1433. php_info_print_table_end();
  1434. }
  1435. }
  1436. /* }}} */
  1437. /* {{{ proto bool virtual(string filename)
  1438. Perform an Apache sub-request */
  1439. /* This function is equivalent to <!--#include virtual...-->
  1440. * in mod_include. It does an Apache sub-request. It is useful
  1441. * for including CGI scripts or .shtml files, or anything else
  1442. * that you'd parse through Apache (for .phtml files, you'd probably
  1443. * want to use <?Include>. This only works when PHP is compiled
  1444. * as an Apache module, since it uses the Apache API for doing
  1445. * sub requests.
  1446. */
  1447. PHP_FUNCTION(virtual)
  1448. {
  1449. pval **filename;
  1450. request_rec *rr = NULL;
  1451. if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) {
  1452. WRONG_PARAM_COUNT;
  1453. }
  1454. convert_to_string_ex(filename);
  1455. if (!(rr = sub_req_lookup_uri ((*filename)->value.str.val, ((request_rec *) SG(server_context))))) {
  1456. php_error(E_WARNING, "Unable to include '%s' - URI lookup failed", (*filename)->value.str.val);
  1457. if (rr) destroy_sub_req (rr);
  1458. RETURN_FALSE;
  1459. }
  1460. if (rr->status != 200) {
  1461. php_error(E_WARNING, "Unable to include '%s' - error finding URI", (*filename)->value.str.val);
  1462. if (rr) destroy_sub_req (rr);
  1463. RETURN_FALSE;
  1464. }
  1465. php_end_ob_buffers(1 TSRMLS_CC);
  1466. php_header(TSRMLS_C);
  1467. if (run_sub_req(rr)) {
  1468. php_error(E_WARNING, "Unable to include '%s' - request execution failed", (*filename)->value.str.val);
  1469. if (rr) destroy_sub_req (rr);
  1470. RETURN_FALSE;
  1471. } else {
  1472. if (rr) destroy_sub_req (rr);
  1473. RETURN_TRUE;
  1474. }
  1475. }
  1476. /* }}} */
  1477. /* {{{ apache_table_to_zval(table *, int safe_mode, zval *return_value)
  1478. Fetch all HTTP request headers */
  1479. static void apache_table_to_zval(table *t, int safe_mode, zval *return_value)
  1480. {
  1481. array_header *env_arr;
  1482. table_entry *tenv;
  1483. int i;
  1484. array_init(return_value);
  1485. env_arr = table_elts(t);
  1486. tenv = (table_entry *)env_arr->elts;
  1487. for (i = 0; i < env_arr->nelts; ++i) {
  1488. if (!tenv[i].key ||
  1489. (safe_mode && !strncasecmp(tenv[i].key, "authorization", 13))) {
  1490. continue;
  1491. }
  1492. if (add_assoc_string(return_value, tenv[i].key, (tenv[i].val==NULL) ? "" : tenv[i].val, 1)==FAILURE) {
  1493. RETURN_FALSE;
  1494. }
  1495. }
  1496. }
  1497. /* }}} */
  1498. /* {{{ proto array getallheaders(void)
  1499. */
  1500. /* Alias for apache_request_headers() */
  1501. /* }}} */
  1502. /* {{{ proto array apache_request_headers(void)
  1503. Fetch all HTTP request headers */
  1504. PHP_FUNCTION(apache_request_headers)
  1505. {
  1506. apache_table_to_zval(((request_rec *)SG(server_context))->headers_in, PG(safe_mode), return_value);
  1507. }
  1508. /* }}} */
  1509. /* {{{ proto array apache_response_headers(void)
  1510. Fetch all HTTP response headers */
  1511. PHP_FUNCTION(apache_response_headers)
  1512. {
  1513. apache_table_to_zval(((request_rec *) SG(server_context))->headers_out, 0, return_value);
  1514. }
  1515. /* }}} */
  1516. /* {{{ proto bool apache_setenv(string variable, string value [, bool walk_to_top])
  1517. Set an Apache subprocess_env variable */
  1518. PHP_FUNCTION(apache_setenv)
  1519. {
  1520. int var_len, val_len, top=0;
  1521. char *var = NULL, *val = NULL;
  1522. request_rec *r = (request_rec *) SG(server_context);
  1523. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|b", &var, &var_len, &val, &val_len, &top) == FAILURE) {
  1524. RETURN_FALSE;
  1525. }
  1526. while(top) {
  1527. if(r->prev) r = r->prev;
  1528. else break;
  1529. }
  1530. ap_table_setn(r->subprocess_env, ap_pstrndup(r->pool, var, var_len), ap_pstrndup(r->pool, val, val_len));
  1531. RETURN_TRUE;
  1532. }
  1533. /* }}} */
  1534. /* {{{ proto object apache_lookup_uri(string URI)
  1535. Perform a partial request of the given URI to obtain information about it */
  1536. PHP_FUNCTION(apache_lookup_uri)
  1537. {
  1538. pval **filename;
  1539. request_rec *rr=NULL;
  1540. if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) {
  1541. WRONG_PARAM_COUNT;
  1542. }
  1543. convert_to_string_ex(filename);
  1544. if(!(rr = sub_req_lookup_uri((*filename)->value.str.val, ((request_rec *) SG(server_context))))) {
  1545. php_error(E_WARNING, "URI lookup failed", (*filename)->value.str.val);
  1546. RETURN_FALSE;
  1547. }
  1548. object_init(return_value);
  1549. add_property_long(return_value,"status", rr->status);
  1550. if (rr->the_request) {
  1551. add_property_string(return_value,"the_request", rr->the_request, 1);
  1552. }
  1553. if (rr->status_line) {
  1554. add_property_string(return_value,"status_line", (char *)rr->status_line, 1);
  1555. }
  1556. if (rr->method) {
  1557. add_property_string(return_value,"method", (char *)rr->method, 1);
  1558. }
  1559. if (rr->content_type) {
  1560. add_property_string(return_value,"content_type", (char *)rr->content_type, 1);
  1561. }
  1562. if (rr->handler) {
  1563. add_property_string(return_value,"handler", (char *)rr->handler, 1);
  1564. }
  1565. if (rr->uri) {
  1566. add_property_string(return_value,"uri", rr->uri, 1);
  1567. }
  1568. if (rr->filename) {
  1569. add_property_string(return_value,"filename", rr->filename, 1);
  1570. }
  1571. if (rr->path_info) {
  1572. add_property_string(return_value,"path_info", rr->path_info, 1);
  1573. }
  1574. if (rr->args) {
  1575. add_property_string(return_value,"args", rr->args, 1);
  1576. }
  1577. if (rr->boundary) {
  1578. add_property_string(return_value,"boundary", rr->boundary, 1);
  1579. }
  1580. add_property_long(return_value,"no_cache", rr->no_cache);
  1581. add_property_long(return_value,"no_local_copy", rr->no_local_copy);
  1582. add_property_long(return_value,"allowed", rr->allowed);
  1583. add_property_long(return_value,"sent_bodyct", rr->sent_bodyct);
  1584. add_property_long(return_value,"bytes_sent", rr->bytes_sent);
  1585. add_property_long(return_value,"byterange", rr->byterange);
  1586. add_property_long(return_value,"clength", rr->clength);
  1587. #if MODULE_MAGIC_NUMBER >= 19980324
  1588. if (rr->unparsed_uri) {
  1589. add_property_string(return_value,"unparsed_uri", rr->unparsed_uri, 1);
  1590. }
  1591. if(rr->mtime) {
  1592. add_property_long(return_value,"mtime", rr->mtime);
  1593. }
  1594. #endif
  1595. if(rr->request_time) {
  1596. add_property_long(return_value,"request_time", rr->request_time);
  1597. }
  1598. destroy_sub_req(rr);
  1599. }
  1600. /* }}} */
  1601. #if 0
  1602. This function is most likely a bad idea. Just playing with it for now.
  1603. PHP_FUNCTION(apache_exec_uri)
  1604. {
  1605. pval **filename;
  1606. request_rec *rr=NULL;
  1607. TSRMLS_FETCH();
  1608. if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) {
  1609. WRONG_PARAM_COUNT;
  1610. }
  1611. convert_to_string_ex(filename);
  1612. if(!(rr = ap_sub_req_lookup_uri((*filename)->value.str.val, ((request_rec *) SG(server_context))))) {
  1613. php_error(E_WARNING, "URI lookup failed", (*filename)->value.str.val);
  1614. RETURN_FALSE;
  1615. }
  1616. RETVAL_LONG(ap_run_sub_req(rr));
  1617. ap_destroy_sub_req(rr);
  1618. }
  1619. #endif
  1620. /* {{{ proto string apache_get_version(void)
  1621. Fetch Apache version */
  1622. PHP_FUNCTION(apache_get_version)
  1623. {
  1624. char *apv = (char *) ap_get_server_version();
  1625. if (apv && *apv) {
  1626. RETURN_STRING(apv, 1);
  1627. } else {
  1628. RETURN_FALSE;
  1629. }
  1630. }
  1631. /* }}} */
  1632. /* {{{ proto array apache_get_modules(void)
  1633. Get a list of loaded Apache modules */
  1634. PHP_FUNCTION(apache_get_modules)
  1635. {
  1636. int n;
  1637. char *p;
  1638. array_init(return_value);
  1639. for (n = 0; ap_loaded_modules[n]; ++n) {
  1640. char *s = (char *) ap_loaded_modules[n]->name;
  1641. if ((p = strchr(s, '.'))) {
  1642. add_next_index_stringl(return_value, s, (p - s), 1);
  1643. } else {
  1644. add_next_index_string(return_value, s, 1);
  1645. }
  1646. }
  1647. }
  1648. /* }}} */
  1649. /*
  1650. * Local variables:
  1651. * tab-width: 4
  1652. * c-basic-offset: 4
  1653. * End:
  1654. * vim600: sw=4 ts=4 fdm=marker
  1655. * vim<600: sw=4 ts=4
  1656. */