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.

1972 lines
54 KiB

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