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.

1978 lines
55 KiB

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
22 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-2009 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 *, 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. 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, 0, 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, 0, 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, 0, 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 ztype;
  590. request_rec *r;
  591. char *res;
  592. int type = REMOTE_NAME;
  593. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &ztype) == FAILURE) {
  594. return;
  595. }
  596. switch (ZEND_NUM_ARGS()) {
  597. case 0:
  598. break;
  599. case 1:
  600. type = ztype;
  601. break;
  602. }
  603. APREQ_GET_REQUEST(id, r);
  604. res = (char *)ap_get_remote_host(r->connection, r->per_dir_config, type);
  605. if (res) {
  606. RETURN_STRING(res, 1);
  607. }
  608. RETURN_EMPTY_STRING();
  609. }
  610. /* }}} */
  611. /* {{{ proto long apache_request_update_mtime([int dependency_mtime])
  612. */
  613. PHP_FUNCTION(apache_request_update_mtime)
  614. {
  615. zval *id;
  616. request_rec *r;
  617. long mtime = 0;
  618. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &mtime) == FAILURE) {
  619. return;
  620. }
  621. APREQ_GET_REQUEST(id, r);
  622. RETURN_LONG(ap_update_mtime(r, (int) mtime));
  623. }
  624. /* }}} */
  625. /* {{{ proto void apache_request_set_etag()
  626. */
  627. PHP_FUNCTION(apache_request_set_etag)
  628. {
  629. zval *id;
  630. request_rec *r;
  631. if (zend_parse_parameters_none() == FAILURE) {
  632. return;
  633. }
  634. APREQ_GET_REQUEST(id, r);
  635. ap_set_etag(r);
  636. RETURN_TRUE;
  637. }
  638. /* }}} */
  639. /* {{{ proto void apache_request_set_last_modified()
  640. */
  641. PHP_FUNCTION(apache_request_set_last_modified)
  642. {
  643. zval *id;
  644. request_rec *r;
  645. if (zend_parse_parameters_none() == FAILURE) {
  646. return;
  647. }
  648. APREQ_GET_REQUEST(id, r);
  649. ap_set_last_modified(r);
  650. RETURN_TRUE;
  651. }
  652. /* }}} */
  653. /* {{{ proto long apache_request_meets_conditions()
  654. */
  655. PHP_FUNCTION(apache_request_meets_conditions)
  656. {
  657. zval *id;
  658. request_rec *r;
  659. if (zend_parse_parameters_none() == FAILURE) {
  660. return;
  661. }
  662. APREQ_GET_REQUEST(id, r);
  663. RETURN_LONG(ap_meets_conditions(r));
  664. }
  665. /* }}} */
  666. /* {{{ proto long apache_request_discard_request_body()
  667. */
  668. PHP_FUNCTION(apache_request_discard_request_body)
  669. {
  670. zval *id;
  671. request_rec *r;
  672. if (zend_parse_parameters_none() == FAILURE) {
  673. return;
  674. }
  675. APREQ_GET_REQUEST(id, r);
  676. RETURN_LONG(ap_discard_request_body(r));
  677. }
  678. /* }}} */
  679. /* {{{ proto long apache_request_satisfies()
  680. */
  681. PHP_FUNCTION(apache_request_satisfies)
  682. {
  683. zval *id;
  684. request_rec *r;
  685. if (zend_parse_parameters_none() == FAILURE) {
  686. return;
  687. }
  688. APREQ_GET_REQUEST(id, r);
  689. RETURN_LONG(ap_satisfies(r));
  690. }
  691. /* }}} */
  692. /* {{{ proto bool apache_request_is_initial_req()
  693. */
  694. PHP_FUNCTION(apache_request_is_initial_req)
  695. {
  696. zval *id;
  697. request_rec *r;
  698. if (zend_parse_parameters_none() == FAILURE) {
  699. return;
  700. }
  701. APREQ_GET_REQUEST(id, r);
  702. RETURN_BOOL(ap_is_initial_req(r));
  703. }
  704. /* }}} */
  705. /* {{{ proto bool apache_request_some_auth_required()
  706. */
  707. PHP_FUNCTION(apache_request_some_auth_required)
  708. {
  709. zval *id;
  710. request_rec *r;
  711. if (zend_parse_parameters_none() == FAILURE) {
  712. return;
  713. }
  714. APREQ_GET_REQUEST(id, r);
  715. RETURN_BOOL(ap_some_auth_required(r));
  716. }
  717. /* }}} */
  718. /* {{{ proto string apache_request_auth_type()
  719. */
  720. PHP_FUNCTION(apache_request_auth_type)
  721. {
  722. zval *id;
  723. request_rec *r;
  724. char *t;
  725. if (zend_parse_parameters_none() == FAILURE) {
  726. return;
  727. }
  728. APREQ_GET_REQUEST(id, r);
  729. t = (char *)ap_auth_type(r);
  730. if (!t) {
  731. RETURN_NULL();
  732. }
  733. RETURN_STRING(t, 1);
  734. }
  735. /* }}} */
  736. /* {{{ proto string apache_request_auth_name()
  737. */
  738. PHP_FUNCTION(apache_request_auth_name)
  739. {
  740. zval *id;
  741. request_rec *r;
  742. char *t;
  743. if (zend_parse_parameters_none() == FAILURE) {
  744. return;
  745. }
  746. APREQ_GET_REQUEST(id, r);
  747. t = (char *)ap_auth_name(r);
  748. if (!t) {
  749. RETURN_NULL();
  750. }
  751. RETURN_STRING(t, 1);
  752. }
  753. /* }}} */
  754. /* {{{ proto apache_request_basic_auth_pw()
  755. */
  756. PHP_FUNCTION(apache_request_basic_auth_pw)
  757. {
  758. zval *id, *zpw;
  759. request_rec *r;
  760. const char *pw;
  761. long status;
  762. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zpw) == FAILURE) {
  763. return;
  764. }
  765. if (!PZVAL_IS_REF(zpw)) {
  766. zend_error(E_WARNING, "Parameter wasn't passed by reference");
  767. RETURN_NULL();
  768. }
  769. APREQ_GET_REQUEST(id, r);
  770. pw = NULL;
  771. status = ap_get_basic_auth_pw(r, &pw);
  772. if (status == OK && pw) {
  773. ZVAL_STRING(zpw, (char *)pw, 1);
  774. } else {
  775. ZVAL_NULL(zpw);
  776. }
  777. RETURN_LONG(status);
  778. }
  779. /* }}} */
  780. /* http_protocol.h */
  781. PHP_FUNCTION(apache_request_send_http_header)
  782. {
  783. zval *id;
  784. request_rec *r;
  785. char *type = NULL;
  786. int typelen;
  787. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &type, &typelen) == FAILURE) {
  788. return;
  789. }
  790. APREQ_GET_REQUEST(id, r);
  791. if(type) {
  792. r->content_type = pstrdup(r->pool, type);
  793. }
  794. ap_send_http_header(r);
  795. SG(headers_sent) = 1;
  796. AP(headers_sent) = 1;
  797. RETURN_TRUE;
  798. }
  799. PHP_FUNCTION(apache_request_basic_http_header)
  800. {
  801. zval *id;
  802. request_rec *r;
  803. if (zend_parse_parameters_none() == FAILURE) {
  804. return;
  805. }
  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. if (zend_parse_parameters_none() == FAILURE) {
  817. return;
  818. }
  819. APREQ_GET_REQUEST(id, r);
  820. ap_send_http_trace((request_rec *)SG(server_context));
  821. SG(headers_sent) = 1;
  822. AP(headers_sent) = 1;
  823. RETURN_TRUE;
  824. }
  825. PHP_FUNCTION(apache_request_send_http_options)
  826. {
  827. zval *id;
  828. request_rec *r;
  829. if (zend_parse_parameters_none() == FAILURE) {
  830. return;
  831. }
  832. APREQ_GET_REQUEST(id, r);
  833. ap_send_http_options((request_rec *)SG(server_context));
  834. SG(headers_sent) = 1;
  835. AP(headers_sent) = 1;
  836. RETURN_TRUE;
  837. }
  838. PHP_FUNCTION(apache_request_send_error_response)
  839. {
  840. zval *id;
  841. request_rec *r;
  842. long rec = 0;
  843. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &rec) == FAILURE) {
  844. return;
  845. }
  846. APREQ_GET_REQUEST(id, r);
  847. ap_send_error_response(r, (int) rec);
  848. RETURN_TRUE;
  849. }
  850. PHP_FUNCTION(apache_request_set_content_length)
  851. {
  852. long length;
  853. zval *id;
  854. request_rec *r;
  855. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &length) == FAILURE) {
  856. return;
  857. }
  858. APREQ_GET_REQUEST(id, r);
  859. ap_set_content_length(r, length);
  860. RETURN_TRUE;
  861. }
  862. PHP_FUNCTION(apache_request_set_keepalive)
  863. {
  864. zval *id;
  865. request_rec *r;
  866. if (zend_parse_parameters_none() == FAILURE) {
  867. return;
  868. }
  869. APREQ_GET_REQUEST(id, r);
  870. ap_set_keepalive(r);
  871. RETURN_TRUE;
  872. }
  873. /* This stuff should use streams or however this is implemented now
  874. PHP_FUNCTION(apache_request_send_fd)
  875. {
  876. }
  877. PHP_FUNCTION(apache_request_send_fd_length)
  878. {
  879. }
  880. */
  881. /* These are for overriding default output behaviour */
  882. PHP_FUNCTION(apache_request_rputs)
  883. {
  884. char *buffer;
  885. int buffer_len;
  886. zval *id;
  887. request_rec *r;
  888. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &buffer, &buffer_len) == FAILURE) {
  889. return;
  890. }
  891. APREQ_GET_REQUEST(id, r);
  892. ap_rwrite(buffer, buffer_len, (request_rec*)SG(server_context));
  893. }
  894. /* This stuff would be useful for custom POST handlers,
  895. which should be supported. Probably by not using
  896. sapi_activate at all inside a phpResponseHandler
  897. and instead using a builtin composed of the below
  898. calls as a apache_read_request_body() and allow
  899. people to custom craft their own.
  900. PHP_FUNCTION(apache_request_setup_client_block)
  901. {
  902. }
  903. PHP_FUNCTION(apache_request_should_client_block)
  904. {
  905. }
  906. PHP_FUNCTION(apache_request_get_client_block)
  907. {
  908. }
  909. PHP_FUNCTION(apache_request_discard_request_body)
  910. {
  911. }
  912. */
  913. /* http_log.h */
  914. /* {{{ proto boolean apache_request_log_error(string message, [long facility])
  915. */
  916. PHP_FUNCTION(apache_request_log_error)
  917. {
  918. zval *id;
  919. char *z_errstr;
  920. int z_errstr_len;
  921. long facility = APLOG_ERR;
  922. request_rec *r;
  923. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &z_errstr, &z_errstr_len, &facility) == FAILURE) {
  924. return;
  925. }
  926. APREQ_GET_REQUEST(id, r);
  927. ap_log_error(APLOG_MARK, (int) facility, r->server, "%s", z_errstr);
  928. RETURN_TRUE;
  929. }
  930. /* }}} */
  931. /* http_main.h */
  932. /* {{{ proto object apache_request_sub_req_lookup_uri(string uri)
  933. Returns sub-request for the specified uri. You would
  934. need to run it yourself with run()
  935. */
  936. PHP_FUNCTION(apache_request_sub_req_lookup_uri)
  937. {
  938. zval *id;
  939. char *file;
  940. int file_len;
  941. request_rec *r, *sub_r;
  942. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) {
  943. return;
  944. }
  945. APREQ_GET_REQUEST(id, r);
  946. sub_r = ap_sub_req_lookup_uri(file, r);
  947. if (!sub_r) {
  948. RETURN_FALSE;
  949. }
  950. return_value = php_apache_request_new(sub_r);
  951. }
  952. /* }}} */
  953. /* {{{ proto object apache_request_sub_req_lookup_file(string file)
  954. Returns sub-request for the specified file. You would
  955. need to run it yourself with run().
  956. */
  957. PHP_FUNCTION(apache_request_sub_req_lookup_file)
  958. {
  959. zval *id;
  960. char *file;
  961. int file_len;
  962. request_rec *r, *sub_r;
  963. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) {
  964. return;
  965. }
  966. APREQ_GET_REQUEST(id, r);
  967. sub_r = ap_sub_req_lookup_file(file, r);
  968. if (!sub_r) {
  969. RETURN_FALSE;
  970. }
  971. return_value = php_apache_request_new(sub_r);
  972. }
  973. /* }}} */
  974. /* {{{ proto object apache_request_sub_req_method_uri(string method, string uri)
  975. Returns sub-request for the specified file. You would
  976. need to run it yourself with run().
  977. */
  978. PHP_FUNCTION(apache_request_sub_req_method_uri)
  979. {
  980. zval *id;
  981. char *file, *method;
  982. int file_len, method_len;
  983. request_rec *r, *sub_r;
  984. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &method, &method_len, &file, &file_len) == FAILURE) {
  985. return;
  986. }
  987. APREQ_GET_REQUEST(id, r);
  988. sub_r = ap_sub_req_method_uri(method, file, r);
  989. if (!sub_r) {
  990. RETURN_FALSE;
  991. }
  992. return_value = php_apache_request_new(sub_r);
  993. }
  994. /* }}} */
  995. /* {{{ proto long apache_request_run()
  996. This is a wrapper for ap_sub_run_req and ap_destory_sub_req. It takes
  997. sub_request, runs it, destroys it, and returns it's status.
  998. */
  999. PHP_FUNCTION(apache_request_run)
  1000. {
  1001. zval *id;
  1002. request_rec *r;
  1003. int status;
  1004. if (zend_parse_parameters_none() == FAILURE) {
  1005. return;
  1006. }
  1007. APREQ_GET_REQUEST(id, r);
  1008. if (!r || ap_is_initial_req(r)) {
  1009. RETURN_FALSE;
  1010. }
  1011. status = ap_run_sub_req(r);
  1012. ap_destroy_sub_req(r);
  1013. RETURN_LONG(status);
  1014. }
  1015. /* }}} */
  1016. PHP_FUNCTION(apache_request_internal_redirect)
  1017. {
  1018. zval *id;
  1019. char *new_uri;
  1020. int new_uri_len;
  1021. request_rec *r;
  1022. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &new_uri, &new_uri_len) == FAILURE) {
  1023. return;
  1024. }
  1025. APREQ_GET_REQUEST(id, r);
  1026. ap_internal_redirect(new_uri, r);
  1027. }
  1028. PHP_FUNCTION(apache_request_send_header_field)
  1029. {
  1030. char *fieldname, *fieldval;
  1031. int fieldname_len, fieldval_len;
  1032. zval *id;
  1033. request_rec *r;
  1034. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &fieldname, &fieldname_len, &fieldval, &fieldval_len) == FAILURE) {
  1035. return;
  1036. }
  1037. APREQ_GET_REQUEST(id, r);
  1038. ap_send_header_field(r, fieldname, fieldval);
  1039. SG(headers_sent) = 1;
  1040. AP(headers_sent) = 1;
  1041. }
  1042. /* }}} */
  1043. /* {{{ php_apache_request_class_functions
  1044. */
  1045. const static zend_function_entry php_apache_request_class_functions[] = {
  1046. /* string slots */
  1047. PHP_FALIAS(args, apache_request_args, NULL)
  1048. PHP_FALIAS(boundary, apache_request_boundary, NULL)
  1049. PHP_FALIAS(content_encoding, apache_request_content_encoding, NULL)
  1050. PHP_FALIAS(content_type, apache_request_content_type, NULL)
  1051. PHP_FALIAS(filename, apache_request_filename, NULL)
  1052. PHP_FALIAS(handler, apache_request_handler, NULL)
  1053. PHP_FALIAS(hostname, apache_request_hostname, NULL)
  1054. PHP_FALIAS(method, apache_request_method, NULL)
  1055. PHP_FALIAS(path_info, apache_request_path_info, NULL)
  1056. PHP_FALIAS(protocol, apache_request_protocol, NULL)
  1057. PHP_FALIAS(status_line, apache_request_status_line, NULL)
  1058. PHP_FALIAS(the_request, apache_request_the_request, NULL)
  1059. PHP_FALIAS(unparsed_uri, apache_request_unparsed_uri, NULL)
  1060. PHP_FALIAS(uri, apache_request_uri, NULL)
  1061. /* int slots */
  1062. PHP_FALIAS(allowed, apache_request_allowed, NULL)
  1063. PHP_FALIAS(bytes_sent, apache_request_bytes_sent, NULL)
  1064. PHP_FALIAS(chunked, apache_request_chunked, NULL)
  1065. PHP_FALIAS(content_length, apache_request_content_length, NULL)
  1066. PHP_FALIAS(header_only, apache_request_header_only, NULL)
  1067. PHP_FALIAS(method_number, apache_request_method_number, NULL)
  1068. PHP_FALIAS(mtime, apache_request_mtime, NULL)
  1069. PHP_FALIAS(no_cache, apache_request_no_cache, NULL)
  1070. PHP_FALIAS(no_local_copy, apache_request_no_local_copy, NULL)
  1071. PHP_FALIAS(proto_num, apache_request_proto_num, NULL)
  1072. PHP_FALIAS(proxyreq, apache_request_proxyreq, NULL)
  1073. PHP_FALIAS(read_body, apache_request_read_body, NULL)
  1074. PHP_FALIAS(remaining, apache_request_remaining, NULL)
  1075. PHP_FALIAS(request_time, apache_request_request_time, NULL)
  1076. PHP_FALIAS(status, apache_request_status, NULL)
  1077. /* tables & arrays */
  1078. PHP_FALIAS(headers_in, apache_request_headers_in, NULL)
  1079. PHP_FALIAS(headers_out, apache_request_headers_out, NULL)
  1080. PHP_FALIAS(err_headers_out, apache_request_err_headers_out, NULL)
  1081. /* proxy functions for the ap_* functions family */
  1082. #undef auth_name
  1083. #undef auth_type
  1084. #undef discard_request_body
  1085. #undef is_initial_req
  1086. #undef meets_conditions
  1087. #undef satisfies
  1088. #undef set_etag
  1089. #undef set_last_modified
  1090. #undef some_auth_required
  1091. #undef update_mtime
  1092. #undef send_http_header
  1093. #undef send_header_field
  1094. #undef basic_http_header
  1095. #undef send_http_trace
  1096. #undef send_http_options
  1097. #undef send_error_response
  1098. #undef set_content_length
  1099. #undef set_keepalive
  1100. #undef rputs
  1101. #undef log_error
  1102. #undef lookup_uri
  1103. #undef lookup_file
  1104. #undef method_uri
  1105. #undef run
  1106. #undef internal_redirect
  1107. PHP_FALIAS(auth_name, apache_request_auth_name, NULL)
  1108. PHP_FALIAS(auth_type, apache_request_auth_type, NULL)
  1109. PHP_FALIAS(basic_auth_pw, apache_request_basic_auth_pw, NULL)
  1110. PHP_FALIAS(discard_request_body, apache_request_discard_request_body, NULL)
  1111. PHP_FALIAS(is_initial_req, apache_request_is_initial_req, NULL)
  1112. PHP_FALIAS(meets_conditions, apache_request_meets_conditions, NULL)
  1113. PHP_FALIAS(remote_host, apache_request_remote_host, NULL)
  1114. PHP_FALIAS(satisfies, apache_request_satisfies, NULL)
  1115. PHP_FALIAS(server_port, apache_request_server_port, NULL)
  1116. PHP_FALIAS(set_etag, apache_request_set_etag, NULL)
  1117. PHP_FALIAS(set_last_modified, apache_request_set_last_modified, NULL)
  1118. PHP_FALIAS(some_auth_required, apache_request_some_auth_required, NULL)
  1119. PHP_FALIAS(update_mtime, apache_request_update_mtime, NULL)
  1120. PHP_FALIAS(send_http_header, apache_request_send_http_header, NULL)
  1121. PHP_FALIAS(basic_http_header, apache_request_basic_http_header, NULL)
  1122. PHP_FALIAS(send_header_field, apache_request_send_header_field, NULL)
  1123. PHP_FALIAS(send_http_trace, apache_request_send_http_trace, NULL)
  1124. PHP_FALIAS(send_http_options, apache_request_send_http_trace, NULL)
  1125. PHP_FALIAS(send_error_response, apache_request_send_error_response, NULL)
  1126. PHP_FALIAS(set_content_length, apache_request_set_content_length, NULL)
  1127. PHP_FALIAS(set_keepalive, apache_request_set_keepalive, NULL)
  1128. PHP_FALIAS(rputs, apache_request_rputs, NULL)
  1129. PHP_FALIAS(log_error, apache_request_log_error, NULL)
  1130. PHP_FALIAS(lookup_uri, apache_request_sub_req_lookup_uri, NULL)
  1131. PHP_FALIAS(lookup_file, apache_request_sub_req_lookup_file, NULL)
  1132. PHP_FALIAS(method_uri, apache_request_sub_req_method_uri, NULL)
  1133. PHP_FALIAS(run, apache_request_run, NULL)
  1134. PHP_FALIAS(internal_redirect, apache_request_internal_redirect, NULL)
  1135. { NULL, NULL, NULL }
  1136. };
  1137. /* }}} */
  1138. static PHP_MINIT_FUNCTION(apache)
  1139. {
  1140. zend_class_entry ce;
  1141. #ifdef ZTS
  1142. ts_allocate_id(&php_apache_info_id, sizeof(php_apache_info_struct), (ts_allocate_ctor) php_apache_globals_ctor, NULL);
  1143. #else
  1144. php_apache_globals_ctor(&php_apache_info TSRMLS_CC);
  1145. #endif
  1146. REGISTER_INI_ENTRIES();
  1147. le_apachereq = zend_register_list_destructors_ex(php_apache_request_free, NULL, "ApacheRequest", module_number);
  1148. INIT_OVERLOADED_CLASS_ENTRY(ce, "ApacheRequest", php_apache_request_class_functions, NULL, NULL, NULL);
  1149. apacherequest_class_entry = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC);
  1150. REGISTER_LONG_CONSTANT("OK", OK, CONST_CS | CONST_PERSISTENT);
  1151. REGISTER_LONG_CONSTANT("DECLINED", DECLINED, CONST_CS | CONST_PERSISTENT);
  1152. REGISTER_LONG_CONSTANT("FORBIDDEN", FORBIDDEN, CONST_CS | CONST_PERSISTENT);
  1153. REGISTER_LONG_CONSTANT("AUTH_REQUIRED", AUTH_REQUIRED, CONST_CS | CONST_PERSISTENT);
  1154. REGISTER_LONG_CONSTANT("DONE", DONE, CONST_CS | CONST_PERSISTENT);
  1155. REGISTER_LONG_CONSTANT("SERVER_ERROR", SERVER_ERROR, CONST_CS | CONST_PERSISTENT);
  1156. REGISTER_LONG_CONSTANT("REDIRECT", REDIRECT, CONST_CS | CONST_PERSISTENT);
  1157. REGISTER_LONG_CONSTANT("BAD_REQUEST", BAD_REQUEST, CONST_CS | CONST_PERSISTENT);
  1158. REGISTER_LONG_CONSTANT("NOT_FOUND", NOT_FOUND, CONST_CS | CONST_PERSISTENT);
  1159. REGISTER_LONG_CONSTANT("HTTP_CONTINUE", HTTP_CONTINUE, CONST_CS | CONST_PERSISTENT);
  1160. REGISTER_LONG_CONSTANT("HTTP_SWITCHING_PROTOCOLS", HTTP_SWITCHING_PROTOCOLS, CONST_CS | CONST_PERSISTENT);
  1161. REGISTER_LONG_CONSTANT("HTTP_PROCESSING", HTTP_PROCESSING, CONST_CS | CONST_PERSISTENT);
  1162. REGISTER_LONG_CONSTANT("HTTP_OK", HTTP_OK, CONST_CS | CONST_PERSISTENT);
  1163. REGISTER_LONG_CONSTANT("HTTP_CREATED", HTTP_CREATED, CONST_CS | CONST_PERSISTENT);
  1164. REGISTER_LONG_CONSTANT("HTTP_ACCEPTED", HTTP_ACCEPTED, CONST_CS | CONST_PERSISTENT);
  1165. REGISTER_LONG_CONSTANT("HTTP_NON_AUTHORITATIVE", HTTP_NON_AUTHORITATIVE, CONST_CS | CONST_PERSISTENT);
  1166. REGISTER_LONG_CONSTANT("HTTP_NO_CONTENT", HTTP_NO_CONTENT, CONST_CS | CONST_PERSISTENT);
  1167. REGISTER_LONG_CONSTANT("HTTP_RESET_CONTENT", HTTP_RESET_CONTENT, CONST_CS | CONST_PERSISTENT);
  1168. REGISTER_LONG_CONSTANT("HTTP_PARTIAL_CONTENT", HTTP_PARTIAL_CONTENT, CONST_CS | CONST_PERSISTENT);
  1169. REGISTER_LONG_CONSTANT("HTTP_MULTI_STATUS", HTTP_MULTI_STATUS, CONST_CS | CONST_PERSISTENT);
  1170. REGISTER_LONG_CONSTANT("HTTP_MULTIPLE_CHOICES", HTTP_MULTIPLE_CHOICES, CONST_CS | CONST_PERSISTENT);
  1171. REGISTER_LONG_CONSTANT("HTTP_MOVED_PERMANENTLY", HTTP_MOVED_PERMANENTLY, CONST_CS | CONST_PERSISTENT);
  1172. REGISTER_LONG_CONSTANT("HTTP_MOVED_TEMPORARILY", HTTP_MOVED_TEMPORARILY, CONST_CS | CONST_PERSISTENT);
  1173. REGISTER_LONG_CONSTANT("HTTP_SEE_OTHER", HTTP_SEE_OTHER, CONST_CS | CONST_PERSISTENT);
  1174. REGISTER_LONG_CONSTANT("HTTP_NOT_MODIFIED", HTTP_NOT_MODIFIED, CONST_CS | CONST_PERSISTENT);
  1175. REGISTER_LONG_CONSTANT("HTTP_USE_PROXY", HTTP_USE_PROXY, CONST_CS | CONST_PERSISTENT);
  1176. REGISTER_LONG_CONSTANT("HTTP_TEMPORARY_REDIRECT", HTTP_TEMPORARY_REDIRECT, CONST_CS | CONST_PERSISTENT);
  1177. REGISTER_LONG_CONSTANT("HTTP_BAD_REQUEST", HTTP_BAD_REQUEST, CONST_CS | CONST_PERSISTENT);
  1178. REGISTER_LONG_CONSTANT("HTTP_UNAUTHORIZED", HTTP_UNAUTHORIZED, CONST_CS | CONST_PERSISTENT);
  1179. REGISTER_LONG_CONSTANT("HTTP_PAYMENT_REQUIRED", HTTP_PAYMENT_REQUIRED, CONST_CS | CONST_PERSISTENT);
  1180. REGISTER_LONG_CONSTANT("HTTP_FORBIDDEN", HTTP_FORBIDDEN, CONST_CS | CONST_PERSISTENT);
  1181. REGISTER_LONG_CONSTANT("HTTP_NOT_FOUND", HTTP_NOT_FOUND, CONST_CS | CONST_PERSISTENT);
  1182. REGISTER_LONG_CONSTANT("HTTP_METHOD_NOT_ALLOWED", HTTP_METHOD_NOT_ALLOWED, CONST_CS | CONST_PERSISTENT);
  1183. REGISTER_LONG_CONSTANT("HTTP_NOT_ACCEPTABLE", HTTP_NOT_ACCEPTABLE, CONST_CS | CONST_PERSISTENT);
  1184. REGISTER_LONG_CONSTANT("HTTP_PROXY_AUTHENTICATION_REQUIRED", HTTP_PROXY_AUTHENTICATION_REQUIRED, CONST_CS | CONST_PERSISTENT);
  1185. REGISTER_LONG_CONSTANT("HTTP_REQUEST_TIME_OUT", HTTP_REQUEST_TIME_OUT, CONST_CS | CONST_PERSISTENT);
  1186. REGISTER_LONG_CONSTANT("HTTP_CONFLICT", HTTP_CONFLICT, CONST_CS | CONST_PERSISTENT);
  1187. REGISTER_LONG_CONSTANT("HTTP_GONE", HTTP_GONE, CONST_CS | CONST_PERSISTENT);REGISTER_LONG_CONSTANT("HTTP_LENGTH_REQUIRED", HTTP_LENGTH_REQUIRED, CONST_CS | CONST_PERSISTENT);
  1188. REGISTER_LONG_CONSTANT("HTTP_PRECONDITION_FAILED", HTTP_PRECONDITION_FAILED, CONST_CS | CONST_PERSISTENT);
  1189. REGISTER_LONG_CONSTANT("HTTP_REQUEST_ENTITY_TOO_LARGE", HTTP_REQUEST_ENTITY_TOO_LARGE, CONST_CS | CONST_PERSISTENT);
  1190. REGISTER_LONG_CONSTANT("HTTP_REQUEST_URI_TOO_LARGE", HTTP_REQUEST_URI_TOO_LARGE, CONST_CS | CONST_PERSISTENT);
  1191. REGISTER_LONG_CONSTANT("HTTP_UNSUPPORTED_MEDIA_TYPE", HTTP_UNSUPPORTED_MEDIA_TYPE, CONST_CS | CONST_PERSISTENT);
  1192. REGISTER_LONG_CONSTANT("HTTP_RANGE_NOT_SATISFIABLE", HTTP_RANGE_NOT_SATISFIABLE, CONST_CS | CONST_PERSISTENT);
  1193. REGISTER_LONG_CONSTANT("HTTP_EXPECTATION_FAILED", HTTP_EXPECTATION_FAILED, CONST_CS | CONST_PERSISTENT);
  1194. REGISTER_LONG_CONSTANT("HTTP_UNPROCESSABLE_ENTITY", HTTP_UNPROCESSABLE_ENTITY, CONST_CS | CONST_PERSISTENT);
  1195. REGISTER_LONG_CONSTANT("HTTP_LOCKED", HTTP_LOCKED, CONST_CS | CONST_PERSISTENT);
  1196. REGISTER_LONG_CONSTANT("HTTP_FAILED_DEPENDENCY", HTTP_FAILED_DEPENDENCY, CONST_CS | CONST_PERSISTENT);
  1197. REGISTER_LONG_CONSTANT("HTTP_INTERNAL_SERVER_ERROR", HTTP_INTERNAL_SERVER_ERROR, CONST_CS | CONST_PERSISTENT);
  1198. REGISTER_LONG_CONSTANT("HTTP_NOT_IMPLEMENTED", HTTP_NOT_IMPLEMENTED, CONST_CS | CONST_PERSISTENT);
  1199. REGISTER_LONG_CONSTANT("HTTP_BAD_GATEWAY", HTTP_BAD_GATEWAY, CONST_CS | CONST_PERSISTENT);
  1200. REGISTER_LONG_CONSTANT("HTTP_SERVICE_UNAVAILABLE", HTTP_SERVICE_UNAVAILABLE, CONST_CS | CONST_PERSISTENT);
  1201. REGISTER_LONG_CONSTANT("HTTP_GATEWAY_TIME_OUT", HTTP_GATEWAY_TIME_OUT, CONST_CS | CONST_PERSISTENT);
  1202. REGISTER_LONG_CONSTANT("HTTP_VERSION_NOT_SUPPORTED", HTTP_VERSION_NOT_SUPPORTED, CONST_CS | CONST_PERSISTENT);
  1203. REGISTER_LONG_CONSTANT("HTTP_VARIANT_ALSO_VARIES", HTTP_VARIANT_ALSO_VARIES, CONST_CS | CONST_PERSISTENT);
  1204. REGISTER_LONG_CONSTANT("HTTP_INSUFFICIENT_STORAGE", HTTP_INSUFFICIENT_STORAGE, CONST_CS | CONST_PERSISTENT);
  1205. REGISTER_LONG_CONSTANT("HTTP_NOT_EXTENDED", HTTP_NOT_EXTENDED, CONST_CS | CONST_PERSISTENT);
  1206. REGISTER_LONG_CONSTANT("APLOG_EMERG", APLOG_EMERG, CONST_CS | CONST_PERSISTENT);
  1207. REGISTER_LONG_CONSTANT("APLOG_ALERT", APLOG_ALERT, CONST_CS | CONST_PERSISTENT);
  1208. REGISTER_LONG_CONSTANT("APLOG_CRIT", APLOG_CRIT, CONST_CS | CONST_PERSISTENT);
  1209. REGISTER_LONG_CONSTANT("APLOG_ERR", APLOG_ERR, CONST_CS | CONST_PERSISTENT);
  1210. REGISTER_LONG_CONSTANT("APLOG_WARNING", APLOG_WARNING, CONST_CS | CONST_PERSISTENT);
  1211. REGISTER_LONG_CONSTANT("APLOG_NOTICE", APLOG_NOTICE, CONST_CS | CONST_PERSISTENT);
  1212. REGISTER_LONG_CONSTANT("APLOG_INFO", APLOG_INFO, CONST_CS | CONST_PERSISTENT);
  1213. REGISTER_LONG_CONSTANT("APLOG_DEBUG", APLOG_DEBUG, CONST_CS | CONST_PERSISTENT);
  1214. REGISTER_LONG_CONSTANT("M_GET", M_GET, CONST_CS | CONST_PERSISTENT);
  1215. REGISTER_LONG_CONSTANT("M_PUT", M_PUT, CONST_CS | CONST_PERSISTENT);
  1216. REGISTER_LONG_CONSTANT("M_POST", M_POST, CONST_CS | CONST_PERSISTENT);
  1217. REGISTER_LONG_CONSTANT("M_DELETE", M_DELETE, CONST_CS | CONST_PERSISTENT);
  1218. REGISTER_LONG_CONSTANT("M_CONNECT", M_CONNECT, CONST_CS | CONST_PERSISTENT);
  1219. REGISTER_LONG_CONSTANT("M_OPTIONS", M_OPTIONS, CONST_CS | CONST_PERSISTENT);
  1220. REGISTER_LONG_CONSTANT("M_TRACE", M_TRACE, CONST_CS | CONST_PERSISTENT);
  1221. REGISTER_LONG_CONSTANT("M_PATCH", M_PATCH, CONST_CS | CONST_PERSISTENT);
  1222. REGISTER_LONG_CONSTANT("M_PROPFIND", M_PROPFIND, CONST_CS | CONST_PERSISTENT);
  1223. REGISTER_LONG_CONSTANT("M_PROPPATCH", M_PROPPATCH, CONST_CS | CONST_PERSISTENT);
  1224. REGISTER_LONG_CONSTANT("M_MKCOL", M_MKCOL, CONST_CS | CONST_PERSISTENT);
  1225. REGISTER_LONG_CONSTANT("M_COPY", M_COPY, CONST_CS | CONST_PERSISTENT);
  1226. REGISTER_LONG_CONSTANT("M_MOVE", M_MOVE, CONST_CS | CONST_PERSISTENT);
  1227. REGISTER_LONG_CONSTANT("M_LOCK", M_LOCK, CONST_CS | CONST_PERSISTENT);
  1228. REGISTER_LONG_CONSTANT("M_UNLOCK", M_UNLOCK, CONST_CS | CONST_PERSISTENT);
  1229. REGISTER_LONG_CONSTANT("M_INVALID", M_INVALID, CONST_CS | CONST_PERSISTENT);
  1230. /* Possible values for request_rec.read_body (set by handling module):
  1231. * REQUEST_NO_BODY Send 413 error if message has any body
  1232. * REQUEST_CHUNKED_ERROR Send 411 error if body without Content-Length
  1233. * REQUEST_CHUNKED_DECHUNK If chunked, remove the chunks for me.
  1234. * REQUEST_CHUNKED_PASS Pass the chunks to me without removal.
  1235. */
  1236. REGISTER_LONG_CONSTANT("REQUEST_NO_BODY", REQUEST_NO_BODY, CONST_CS | CONST_PERSISTENT);
  1237. REGISTER_LONG_CONSTANT("REQUEST_CHUNKED_ERROR", REQUEST_CHUNKED_ERROR, CONST_CS | CONST_PERSISTENT);
  1238. REGISTER_LONG_CONSTANT("REQUEST_CHUNKED_DECHUNK", REQUEST_CHUNKED_DECHUNK, CONST_CS | CONST_PERSISTENT);
  1239. REGISTER_LONG_CONSTANT("REQUEST_CHUNKED_PASS", REQUEST_CHUNKED_PASS, CONST_CS | CONST_PERSISTENT);
  1240. /* resolve types for remote_host() */
  1241. REGISTER_LONG_CONSTANT("REMOTE_HOST", REMOTE_HOST, CONST_CS | CONST_PERSISTENT);
  1242. REGISTER_LONG_CONSTANT("REMOTE_NAME", REMOTE_NAME, CONST_CS | CONST_PERSISTENT);
  1243. REGISTER_LONG_CONSTANT("REMOTE_NOLOOKUP", REMOTE_NOLOOKUP, CONST_CS | CONST_PERSISTENT);
  1244. REGISTER_LONG_CONSTANT("REMOTE_DOUBLE_REV", REMOTE_DOUBLE_REV, CONST_CS | CONST_PERSISTENT);
  1245. return SUCCESS;
  1246. }
  1247. static PHP_MSHUTDOWN_FUNCTION(apache)
  1248. {
  1249. UNREGISTER_INI_ENTRIES();
  1250. return SUCCESS;
  1251. }
  1252. zend_module_entry apache_module_entry = {
  1253. STANDARD_MODULE_HEADER,
  1254. "apache",
  1255. apache_functions,
  1256. PHP_MINIT(apache),
  1257. PHP_MSHUTDOWN(apache),
  1258. NULL,
  1259. NULL,
  1260. PHP_MINFO(apache),
  1261. NO_VERSION_YET,
  1262. STANDARD_MODULE_PROPERTIES
  1263. };
  1264. /* {{{ proto bool apache_child_terminate(void)
  1265. Terminate apache process after this request */
  1266. PHP_FUNCTION(apache_child_terminate)
  1267. {
  1268. #ifndef MULTITHREAD
  1269. if (AP(terminate_child)) {
  1270. ap_child_terminate( ((request_rec *)SG(server_context)) );
  1271. RETURN_TRUE;
  1272. } else { /* tell them to get lost! */
  1273. php_error(E_WARNING, "apache.child_terminate is disabled");
  1274. RETURN_FALSE;
  1275. }
  1276. #else
  1277. php_error(E_WARNING, "apache_child_terminate() is not supported in this build");
  1278. RETURN_FALSE;
  1279. #endif
  1280. }
  1281. /* }}} */
  1282. /* {{{ proto string apache_note(string note_name [, string note_value])
  1283. Get and set Apache request notes */
  1284. PHP_FUNCTION(apache_note)
  1285. {
  1286. char *arg_name, *arg_val = NULL;
  1287. int arg_name_len, arg_val_len;
  1288. char *note_val;
  1289. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &arg_name, &arg_name_len, &arg_val, &arg_val_len) == FAILURE) {
  1290. return;
  1291. }
  1292. note_val = (char *) table_get(((request_rec *)SG(server_context))->notes, arg_name);
  1293. if (arg_val) {
  1294. table_set(((request_rec *)SG(server_context))->notes, arg_name, arg_val);
  1295. }
  1296. if (!note_val) {
  1297. RETURN_FALSE;
  1298. }
  1299. RETURN_STRING(note_val, 1);
  1300. }
  1301. /* }}} */
  1302. /* {{{ PHP_MINFO_FUNCTION
  1303. */
  1304. PHP_MINFO_FUNCTION(apache)
  1305. {
  1306. module *modp = NULL;
  1307. char output_buf[128];
  1308. #if !defined(WIN32) && !defined(WINNT)
  1309. char name[64];
  1310. char modulenames[1024];
  1311. char *p;
  1312. #endif
  1313. server_rec *serv;
  1314. extern char server_root[MAX_STRING_LEN];
  1315. extern uid_t user_id;
  1316. extern char *user_name;
  1317. extern gid_t group_id;
  1318. extern int max_requests_per_child;
  1319. serv = ((request_rec *) SG(server_context))->server;
  1320. php_info_print_table_start();
  1321. #ifdef PHP_WIN32
  1322. php_info_print_table_row(1, "Apache for Windows 95/NT");
  1323. php_info_print_table_end();
  1324. php_info_print_table_start();
  1325. #elif defined(NETWARE)
  1326. php_info_print_table_row(1, "Apache for NetWare");
  1327. php_info_print_table_end();
  1328. php_info_print_table_start();
  1329. #else
  1330. php_info_print_table_row(2, "APACHE_INCLUDE", PHP_APACHE_INCLUDE);
  1331. php_info_print_table_row(2, "APACHE_TARGET", PHP_APACHE_TARGET);
  1332. #endif
  1333. php_info_print_table_row(2, "Apache Version", SERVER_VERSION);
  1334. #ifdef APACHE_RELEASE
  1335. snprintf(output_buf, sizeof(output_buf), "%d", APACHE_RELEASE);
  1336. php_info_print_table_row(2, "Apache Release", output_buf);
  1337. #endif
  1338. snprintf(output_buf, sizeof(output_buf), "%d", MODULE_MAGIC_NUMBER);
  1339. php_info_print_table_row(2, "Apache API Version", output_buf);
  1340. snprintf(output_buf, sizeof(output_buf), "%s:%u", serv->server_hostname, serv->port);
  1341. php_info_print_table_row(2, "Hostname:Port", output_buf);
  1342. #if !defined(WIN32) && !defined(WINNT)
  1343. snprintf(output_buf, sizeof(output_buf), "%s(%d)/%d", user_name, (int)user_id, (int)group_id);
  1344. php_info_print_table_row(2, "User/Group", output_buf);
  1345. 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);
  1346. php_info_print_table_row(2, "Max Requests", output_buf);
  1347. #endif
  1348. snprintf(output_buf, sizeof(output_buf), "Connection: %d - Keep-Alive: %d", serv->timeout, serv->keep_alive_timeout);
  1349. php_info_print_table_row(2, "Timeouts", output_buf);
  1350. #if !defined(WIN32) && !defined(WINNT)
  1351. /*
  1352. This block seems to be working on NetWare; But it seems to be showing
  1353. all modules instead of just the loaded ones
  1354. */
  1355. php_info_print_table_row(2, "Server Root", server_root);
  1356. strcpy(modulenames, "");
  1357. for(modp = top_module; modp; modp = modp->next) {
  1358. strlcpy(name, modp->name, sizeof(name));
  1359. if ((p = strrchr(name, '.'))) {
  1360. *p='\0'; /* Cut off ugly .c extensions on module names */
  1361. }
  1362. strlcat(modulenames, name, sizeof(modulenames));
  1363. if (modp->next) {
  1364. strlcat(modulenames, ", ", sizeof(modulenames));
  1365. }
  1366. }
  1367. php_info_print_table_row(2, "Loaded Modules", modulenames);
  1368. #endif
  1369. php_info_print_table_end();
  1370. DISPLAY_INI_ENTRIES();
  1371. {
  1372. register int i;
  1373. array_header *arr;
  1374. table_entry *elts;
  1375. request_rec *r;
  1376. r = ((request_rec *) SG(server_context));
  1377. arr = table_elts(r->subprocess_env);
  1378. elts = (table_entry *)arr->elts;
  1379. SECTION("Apache Environment");
  1380. php_info_print_table_start();
  1381. php_info_print_table_header(2, "Variable", "Value");
  1382. for (i=0; i < arr->nelts; i++) {
  1383. php_info_print_table_row(2, elts[i].key, elts[i].val);
  1384. }
  1385. php_info_print_table_end();
  1386. }
  1387. {
  1388. array_header *env_arr;
  1389. table_entry *env;
  1390. int i;
  1391. request_rec *r;
  1392. r = ((request_rec *) SG(server_context));
  1393. SECTION("HTTP Headers Information");
  1394. php_info_print_table_start();
  1395. php_info_print_table_colspan_header(2, "HTTP Request Headers");
  1396. php_info_print_table_row(2, "HTTP Request", r->the_request);
  1397. env_arr = table_elts(r->headers_in);
  1398. env = (table_entry *)env_arr->elts;
  1399. for (i = 0; i < env_arr->nelts; ++i) {
  1400. if (env[i].key && (!PG(safe_mode) || (PG(safe_mode) && strncasecmp(env[i].key, "authorization", 13)))) {
  1401. php_info_print_table_row(2, env[i].key, env[i].val);
  1402. }
  1403. }
  1404. php_info_print_table_colspan_header(2, "HTTP Response Headers");
  1405. env_arr = table_elts(r->headers_out);
  1406. env = (table_entry *)env_arr->elts;
  1407. for(i = 0; i < env_arr->nelts; ++i) {
  1408. if (env[i].key) {
  1409. php_info_print_table_row(2, env[i].key, env[i].val);
  1410. }
  1411. }
  1412. php_info_print_table_end();
  1413. }
  1414. }
  1415. /* }}} */
  1416. /* {{{ proto bool virtual(string filename)
  1417. Perform an Apache sub-request */
  1418. /* This function is equivalent to <!--#include virtual...-->
  1419. * in mod_include. It does an Apache sub-request. It is useful
  1420. * for including CGI scripts or .shtml files, or anything else
  1421. * that you'd parse through Apache (for .phtml files, you'd probably
  1422. * want to use <?Include>. This only works when PHP is compiled
  1423. * as an Apache module, since it uses the Apache API for doing
  1424. * sub requests.
  1425. */
  1426. PHP_FUNCTION(virtual)
  1427. {
  1428. char *filename;
  1429. int filename_len;
  1430. request_rec *rr = NULL;
  1431. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
  1432. return;
  1433. }
  1434. if (!(rr = sub_req_lookup_uri (filename, ((request_rec *) SG(server_context))))) {
  1435. php_error(E_WARNING, "Unable to include '%s' - URI lookup failed", filename);
  1436. if (rr)
  1437. destroy_sub_req (rr);
  1438. RETURN_FALSE;
  1439. }
  1440. if (rr->status != 200) {
  1441. php_error(E_WARNING, "Unable to include '%s' - error finding URI", filename);
  1442. if (rr)
  1443. destroy_sub_req (rr);
  1444. RETURN_FALSE;
  1445. }
  1446. php_end_ob_buffers(1 TSRMLS_CC);
  1447. php_header(TSRMLS_C);
  1448. if (run_sub_req(rr)) {
  1449. php_error(E_WARNING, "Unable to include '%s' - request execution failed", filename);
  1450. if (rr)
  1451. destroy_sub_req (rr);
  1452. RETURN_FALSE;
  1453. }
  1454. if (rr)
  1455. destroy_sub_req (rr);
  1456. RETURN_TRUE;
  1457. }
  1458. /* }}} */
  1459. /* {{{ apache_table_to_zval(table *, int safe_mode, zval *return_value)
  1460. Fetch all HTTP request headers */
  1461. static void apache_table_to_zval(table *t, int safe_mode, zval *return_value)
  1462. {
  1463. array_header *env_arr;
  1464. table_entry *tenv;
  1465. int i;
  1466. array_init(return_value);
  1467. env_arr = table_elts(t);
  1468. tenv = (table_entry *)env_arr->elts;
  1469. for (i = 0; i < env_arr->nelts; ++i) {
  1470. if (!tenv[i].key ||
  1471. (safe_mode && !strncasecmp(tenv[i].key, "authorization", 13))) {
  1472. continue;
  1473. }
  1474. if (add_assoc_string(return_value, tenv[i].key, (tenv[i].val==NULL) ? "" : tenv[i].val, 1)==FAILURE) {
  1475. RETURN_FALSE;
  1476. }
  1477. }
  1478. }
  1479. /* }}} */
  1480. /* {{{ proto array getallheaders(void)
  1481. */
  1482. /* Alias for apache_request_headers() */
  1483. /* }}} */
  1484. /* {{{ proto array apache_request_headers(void)
  1485. Fetch all HTTP request headers */
  1486. PHP_FUNCTION(apache_request_headers)
  1487. {
  1488. if (zend_parse_parameters_none() == FAILURE) {
  1489. return;
  1490. }
  1491. apache_table_to_zval(((request_rec *)SG(server_context))->headers_in, PG(safe_mode), return_value);
  1492. }
  1493. /* }}} */
  1494. /* {{{ proto array apache_response_headers(void)
  1495. Fetch all HTTP response headers */
  1496. PHP_FUNCTION(apache_response_headers)
  1497. {
  1498. if (zend_parse_parameters_none() == FAILURE) {
  1499. return;
  1500. }
  1501. apache_table_to_zval(((request_rec *) SG(server_context))->headers_out, 0, return_value);
  1502. }
  1503. /* }}} */
  1504. /* {{{ proto bool apache_setenv(string variable, string value [, bool walk_to_top])
  1505. Set an Apache subprocess_env variable */
  1506. PHP_FUNCTION(apache_setenv)
  1507. {
  1508. int var_len, val_len;
  1509. zend_bool top=0;
  1510. char *var = NULL, *val = NULL;
  1511. request_rec *r = (request_rec *) SG(server_context);
  1512. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|b", &var, &var_len, &val, &val_len, &top) == FAILURE) {
  1513. RETURN_FALSE;
  1514. }
  1515. while(top) {
  1516. if (r->prev) {
  1517. r = r->prev;
  1518. }
  1519. else break;
  1520. }
  1521. ap_table_setn(r->subprocess_env, ap_pstrndup(r->pool, var, var_len), ap_pstrndup(r->pool, val, val_len));
  1522. RETURN_TRUE;
  1523. }
  1524. /* }}} */
  1525. /* {{{ proto object apache_lookup_uri(string URI)
  1526. Perform a partial request of the given URI to obtain information about it */
  1527. PHP_FUNCTION(apache_lookup_uri)
  1528. {
  1529. char *filename;
  1530. int filename_len;
  1531. request_rec *rr=NULL;
  1532. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
  1533. return;
  1534. }
  1535. if(!(rr = sub_req_lookup_uri(filename, ((request_rec *) SG(server_context))))) {
  1536. php_error(E_WARNING, "URI lookup failed", filename);
  1537. RETURN_FALSE;
  1538. }
  1539. object_init(return_value);
  1540. add_property_long(return_value,"status", rr->status);
  1541. if (rr->the_request) {
  1542. add_property_string(return_value,"the_request", rr->the_request, 1);
  1543. }
  1544. if (rr->status_line) {
  1545. add_property_string(return_value,"status_line", (char *)rr->status_line, 1);
  1546. }
  1547. if (rr->method) {
  1548. add_property_string(return_value,"method", (char *)rr->method, 1);
  1549. }
  1550. if (rr->content_type) {
  1551. add_property_string(return_value,"content_type", (char *)rr->content_type, 1);
  1552. }
  1553. if (rr->handler) {
  1554. add_property_string(return_value,"handler", (char *)rr->handler, 1);
  1555. }
  1556. if (rr->uri) {
  1557. add_property_string(return_value,"uri", rr->uri, 1);
  1558. }
  1559. if (rr->filename) {
  1560. add_property_string(return_value,"filename", rr->filename, 1);
  1561. }
  1562. if (rr->path_info) {
  1563. add_property_string(return_value,"path_info", rr->path_info, 1);
  1564. }
  1565. if (rr->args) {
  1566. add_property_string(return_value,"args", rr->args, 1);
  1567. }
  1568. if (rr->boundary) {
  1569. add_property_string(return_value,"boundary", rr->boundary, 1);
  1570. }
  1571. add_property_long(return_value,"no_cache", rr->no_cache);
  1572. add_property_long(return_value,"no_local_copy", rr->no_local_copy);
  1573. add_property_long(return_value,"allowed", rr->allowed);
  1574. add_property_long(return_value,"sent_bodyct", rr->sent_bodyct);
  1575. add_property_long(return_value,"bytes_sent", rr->bytes_sent);
  1576. add_property_long(return_value,"byterange", rr->byterange);
  1577. add_property_long(return_value,"clength", rr->clength);
  1578. #if MODULE_MAGIC_NUMBER >= 19980324
  1579. if (rr->unparsed_uri) {
  1580. add_property_string(return_value,"unparsed_uri", rr->unparsed_uri, 1);
  1581. }
  1582. if(rr->mtime) {
  1583. add_property_long(return_value,"mtime", rr->mtime);
  1584. }
  1585. #endif
  1586. if(rr->request_time) {
  1587. add_property_long(return_value,"request_time", rr->request_time);
  1588. }
  1589. destroy_sub_req(rr);
  1590. }
  1591. /* }}} */
  1592. #if 0
  1593. This function is most likely a bad idea. Just playing with it for now.
  1594. PHP_FUNCTION(apache_exec_uri)
  1595. {
  1596. zval **filename;
  1597. request_rec *rr=NULL;
  1598. TSRMLS_FETCH();
  1599. if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) {
  1600. WRONG_PARAM_COUNT;
  1601. }
  1602. convert_to_string_ex(filename);
  1603. if(!(rr = ap_sub_req_lookup_uri((*filename)->value.str.val, ((request_rec *) SG(server_context))))) {
  1604. php_error(E_WARNING, "URI lookup failed", (*filename)->value.str.val);
  1605. RETURN_FALSE;
  1606. }
  1607. RETVAL_LONG(ap_run_sub_req(rr));
  1608. ap_destroy_sub_req(rr);
  1609. }
  1610. #endif
  1611. /* {{{ proto string apache_get_version(void)
  1612. Fetch Apache version */
  1613. PHP_FUNCTION(apache_get_version)
  1614. {
  1615. char *apv = (char *) ap_get_server_version();
  1616. if (apv && *apv) {
  1617. RETURN_STRING(apv, 1);
  1618. } else {
  1619. RETURN_FALSE;
  1620. }
  1621. }
  1622. /* }}} */
  1623. /* {{{ proto array apache_get_modules(void)
  1624. Get a list of loaded Apache modules */
  1625. PHP_FUNCTION(apache_get_modules)
  1626. {
  1627. int n;
  1628. char *p;
  1629. array_init(return_value);
  1630. for (n = 0; ap_loaded_modules[n]; ++n) {
  1631. char *s = (char *) ap_loaded_modules[n]->name;
  1632. if ((p = strchr(s, '.'))) {
  1633. add_next_index_stringl(return_value, s, (p - s), 1);
  1634. } else {
  1635. add_next_index_string(return_value, s, 1);
  1636. }
  1637. }
  1638. }
  1639. /* }}} */
  1640. /*
  1641. * Local variables:
  1642. * tab-width: 4
  1643. * c-basic-offset: 4
  1644. * End:
  1645. * vim600: sw=4 ts=4 fdm=marker
  1646. * vim<600: sw=4 ts=4
  1647. */