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.

3158 lines
87 KiB

27 years ago
27 years ago
27 years ago
24 years ago
25 years ago
25 years ago
25 years ago
23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
22 years ago
23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
26 years ago
23 years ago
26 years ago
23 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
27 years ago
26 years ago
26 years ago
27 years ago
25 years ago
25 years ago
26 years ago
23 years ago
24 years ago
26 years ago
27 years ago
26 years ago
26 years ago
27 years ago
26 years ago
26 years ago
27 years ago
26 years ago
26 years ago
25 years ago
26 years ago
26 years ago
27 years ago
25 years ago
26 years ago
26 years ago
27 years ago
26 years ago
27 years ago
26 years ago
26 years ago
27 years ago
26 years ago
26 years ago
27 years ago
26 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
27 years ago
23 years ago
24 years ago
24 years ago
26 years ago
23 years ago
27 years ago
23 years ago
25 years ago
26 years ago
23 years ago
25 years ago
23 years ago
26 years ago
25 years ago
26 years ago
24 years ago
24 years ago
24 years ago
24 years ago
24 years ago
24 years ago
26 years ago
26 years ago
23 years ago
26 years ago
26 years ago
23 years ago
23 years ago
26 years ago
24 years ago
24 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
23 years ago
23 years ago
23 years ago
24 years ago
24 years ago
24 years ago
25 years ago
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2004 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.0 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_0.txt. |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Andi Gutmans <andi@zend.com> |
  16. | Zeev Suraski <zeev@zend.com> |
  17. +----------------------------------------------------------------------+
  18. */
  19. /* $Id$ */
  20. #include "php.h"
  21. #include "php_streams.h"
  22. #include "php_main.h"
  23. #include "php_globals.h"
  24. #include "php_ini.h"
  25. #include "internal_functions_registry.h"
  26. #include "php_standard.h"
  27. #include "php_math.h"
  28. #include "php_http.h"
  29. #include "php_incomplete_class.h"
  30. #include "ext/standard/info.h"
  31. #include "ext/session/php_session.h"
  32. #include "zend_operators.h"
  33. #include "ext/standard/dns.h"
  34. #include "ext/standard/php_uuencode.h"
  35. typedef struct yy_buffer_state *YY_BUFFER_STATE;
  36. #include "zend.h"
  37. #include "zend_language_scanner.h"
  38. #include "zend_language_parser.h"
  39. #include <stdarg.h>
  40. #include <stdlib.h>
  41. #include <math.h>
  42. #include <time.h>
  43. #include <stdio.h>
  44. #ifndef NETWARE
  45. #include <netdb.h>
  46. #else
  47. /*#include "netware/env.h"*/ /* Temporary */
  48. #ifdef NEW_LIBC /* Same headers hold good for Winsock and Berkeley sockets */
  49. #include <netinet/in.h>
  50. /*#include <arpa/inet.h>*/
  51. #include <netdb.h>
  52. #else
  53. #include <sys/socket.h>
  54. #endif
  55. #endif
  56. #if HAVE_ARPA_INET_H
  57. # include <arpa/inet.h>
  58. #endif
  59. #if HAVE_UNISTD_H
  60. # include <unistd.h>
  61. #endif
  62. #if HAVE_STRING_H
  63. # include <string.h>
  64. #else
  65. # include <strings.h>
  66. #endif
  67. #if HAVE_LOCALE_H
  68. # include <locale.h>
  69. #endif
  70. #if HAVE_SYS_MMAN_H
  71. # include <sys/mman.h>
  72. #endif
  73. #ifdef HARTMUT_0
  74. #include <getopt.h>
  75. #endif
  76. #include "safe_mode.h"
  77. #ifdef PHP_WIN32
  78. # include "win32/unistd.h"
  79. #endif
  80. #ifndef INADDR_NONE
  81. #define INADDR_NONE ((unsigned long int) -1)
  82. #endif
  83. #include "zend_globals.h"
  84. #include "php_globals.h"
  85. #include "SAPI.h"
  86. #include "php_ticks.h"
  87. #ifdef ZTS
  88. int basic_globals_id;
  89. #else
  90. php_basic_globals basic_globals;
  91. #endif
  92. #include "php_fopen_wrappers.h"
  93. #include "streamsfuncs.h"
  94. static
  95. ZEND_BEGIN_ARG_INFO(first_and_second__args_force_ref, 0)
  96. ZEND_ARG_PASS_INFO(1)
  97. ZEND_ARG_PASS_INFO(1)
  98. ZEND_END_ARG_INFO()
  99. static
  100. ZEND_BEGIN_ARG_INFO(second_and_third_args_force_ref, 0)
  101. ZEND_ARG_PASS_INFO(0)
  102. ZEND_ARG_PASS_INFO(1)
  103. ZEND_ARG_PASS_INFO(1)
  104. ZEND_END_ARG_INFO()
  105. static
  106. ZEND_BEGIN_ARG_INFO(third_and_fourth_args_force_ref, 0)
  107. ZEND_ARG_PASS_INFO(0)
  108. ZEND_ARG_PASS_INFO(0)
  109. ZEND_ARG_PASS_INFO(1)
  110. ZEND_ARG_PASS_INFO(1)
  111. ZEND_END_ARG_INFO()
  112. static
  113. ZEND_BEGIN_ARG_INFO(third_and_rest_force_ref, 1)
  114. ZEND_ARG_PASS_INFO(0)
  115. ZEND_ARG_PASS_INFO(0)
  116. ZEND_ARG_PASS_INFO(1)
  117. ZEND_END_ARG_INFO()
  118. static
  119. ZEND_BEGIN_ARG_INFO(first_through_third_args_force_ref, 0)
  120. ZEND_ARG_PASS_INFO(1)
  121. ZEND_ARG_PASS_INFO(1)
  122. ZEND_ARG_PASS_INFO(1)
  123. ZEND_END_ARG_INFO()
  124. typedef struct _php_shutdown_function_entry {
  125. zval **arguments;
  126. int arg_count;
  127. } php_shutdown_function_entry;
  128. typedef struct _user_tick_function_entry {
  129. zval **arguments;
  130. int arg_count;
  131. int calling;
  132. } user_tick_function_entry;
  133. /* some prototypes for local functions */
  134. static void user_shutdown_function_dtor(php_shutdown_function_entry *shutdown_function_entry);
  135. static void user_tick_function_dtor(user_tick_function_entry *tick_function_entry);
  136. function_entry basic_functions[] = {
  137. PHP_FE(constant, NULL)
  138. PHP_FE(bin2hex, NULL)
  139. PHP_FE(sleep, NULL)
  140. PHP_FE(usleep, NULL)
  141. #if HAVE_NANOSLEEP
  142. PHP_FE(time_nanosleep, NULL)
  143. #endif
  144. PHP_FE(time, NULL)
  145. PHP_FE(mktime, NULL)
  146. PHP_FE(gmmktime, NULL)
  147. #if HAVE_STRFTIME
  148. PHP_FE(strftime, NULL)
  149. PHP_FE(gmstrftime, NULL)
  150. #endif
  151. PHP_FE(strtotime, NULL)
  152. PHP_FE(date, NULL)
  153. PHP_FE(idate, NULL)
  154. PHP_FE(gmdate, NULL)
  155. PHP_FE(getdate, NULL)
  156. PHP_FE(localtime, NULL)
  157. PHP_FE(checkdate, NULL)
  158. PHP_FE(flush, NULL)
  159. PHP_FE(wordwrap, NULL)
  160. PHP_FE(htmlspecialchars, NULL)
  161. PHP_FE(htmlentities, NULL)
  162. PHP_FE(html_entity_decode, NULL)
  163. PHP_FE(get_html_translation_table, NULL)
  164. PHP_FE(sha1, NULL)
  165. PHP_FE(sha1_file, NULL)
  166. PHP_NAMED_FE(md5,php_if_md5, NULL)
  167. PHP_NAMED_FE(md5_file,php_if_md5_file, NULL)
  168. PHP_NAMED_FE(crc32,php_if_crc32, NULL)
  169. PHP_FE(iptcparse, NULL)
  170. PHP_FE(iptcembed, NULL)
  171. PHP_FE(getimagesize, second_arg_force_ref)
  172. PHP_FE(image_type_to_mime_type, NULL)
  173. PHP_FE(phpinfo, NULL)
  174. PHP_FE(phpversion, NULL)
  175. PHP_FE(phpcredits, NULL)
  176. PHP_FE(php_logo_guid, NULL)
  177. PHP_FE(php_real_logo_guid, NULL)
  178. PHP_FE(php_egg_logo_guid, NULL)
  179. PHP_FE(zend_logo_guid, NULL)
  180. PHP_FE(php_sapi_name, NULL)
  181. PHP_FE(php_uname, NULL)
  182. PHP_FE(php_ini_scanned_files, NULL)
  183. PHP_FE(strnatcmp, NULL)
  184. PHP_FE(strnatcasecmp, NULL)
  185. PHP_FE(substr_count, NULL)
  186. PHP_FE(strspn, NULL)
  187. PHP_FE(strcspn, NULL)
  188. PHP_FE(strtok, NULL)
  189. PHP_FE(strtoupper, NULL)
  190. PHP_FE(strtolower, NULL)
  191. PHP_FE(strpos, NULL)
  192. PHP_FE(stripos, NULL)
  193. PHP_FE(strrpos, NULL)
  194. PHP_FE(strripos, NULL)
  195. PHP_FE(strrev, NULL)
  196. PHP_FE(hebrev, NULL)
  197. PHP_FE(hebrevc, NULL)
  198. PHP_FE(nl2br, NULL)
  199. PHP_FE(basename, NULL)
  200. PHP_FE(dirname, NULL)
  201. PHP_FE(pathinfo, NULL)
  202. PHP_FE(stripslashes, NULL)
  203. PHP_FE(stripcslashes, NULL)
  204. PHP_FE(strstr, NULL)
  205. PHP_FE(stristr, NULL)
  206. PHP_FE(strrchr, NULL)
  207. PHP_FE(str_shuffle, NULL)
  208. PHP_FE(str_word_count, NULL)
  209. PHP_FE(str_split, NULL)
  210. PHP_FE(strpbrk, NULL)
  211. PHP_FE(substr_compare, NULL)
  212. #ifdef HAVE_STRCOLL
  213. PHP_FE(strcoll, NULL)
  214. #endif
  215. #ifdef HAVE_STRFMON
  216. PHP_FE(money_format, NULL)
  217. #endif
  218. PHP_FE(substr, NULL)
  219. PHP_FE(substr_replace, NULL)
  220. PHP_FE(quotemeta, NULL)
  221. PHP_FE(ucfirst, NULL)
  222. PHP_FE(ucwords, NULL)
  223. PHP_FE(strtr, NULL)
  224. PHP_FE(addslashes, NULL)
  225. PHP_FE(addcslashes, NULL)
  226. PHP_FE(rtrim, NULL)
  227. PHP_FE(str_replace, fourth_arg_force_ref)
  228. PHP_FE(str_ireplace, fourth_arg_force_ref)
  229. PHP_FE(str_repeat, NULL)
  230. PHP_FE(count_chars, NULL)
  231. PHP_FE(chunk_split, NULL)
  232. PHP_FE(trim, NULL)
  233. PHP_FE(ltrim, NULL)
  234. PHP_FE(strip_tags, NULL)
  235. PHP_FE(similar_text, third_arg_force_ref)
  236. PHP_FE(explode, NULL)
  237. PHP_FE(implode, NULL)
  238. PHP_FE(setlocale, NULL)
  239. PHP_FE(localeconv, NULL)
  240. #if HAVE_NL_LANGINFO
  241. PHP_FE(nl_langinfo, NULL)
  242. #endif
  243. PHP_FE(soundex, NULL)
  244. PHP_FE(levenshtein, NULL)
  245. PHP_FE(chr, NULL)
  246. PHP_FE(ord, NULL)
  247. PHP_FE(parse_str, second_arg_force_ref)
  248. PHP_FE(str_pad, NULL)
  249. PHP_FALIAS(chop, rtrim, NULL)
  250. PHP_FALIAS(strchr, strstr, NULL)
  251. PHP_NAMED_FE(sprintf, PHP_FN(user_sprintf), NULL)
  252. PHP_NAMED_FE(printf, PHP_FN(user_printf), NULL)
  253. PHP_FE(vprintf, NULL)
  254. PHP_FE(vsprintf, NULL)
  255. PHP_FE(fprintf, NULL)
  256. PHP_FE(vfprintf, NULL)
  257. PHP_FE(sscanf, third_and_rest_force_ref)
  258. PHP_FE(fscanf, third_and_rest_force_ref)
  259. PHP_FE(parse_url, NULL)
  260. PHP_FE(urlencode, NULL)
  261. PHP_FE(urldecode, NULL)
  262. PHP_FE(rawurlencode, NULL)
  263. PHP_FE(rawurldecode, NULL)
  264. PHP_FE(http_build_query, NULL)
  265. #ifdef HAVE_SYMLINK
  266. PHP_FE(readlink, NULL)
  267. PHP_FE(linkinfo, NULL)
  268. PHP_FE(symlink, NULL)
  269. PHP_FE(link, NULL)
  270. #endif
  271. PHP_FE(unlink, NULL)
  272. PHP_FE(exec, second_and_third_args_force_ref)
  273. PHP_FE(system, second_arg_force_ref)
  274. PHP_FE(escapeshellcmd, NULL)
  275. PHP_FE(escapeshellarg, NULL)
  276. PHP_FE(passthru, second_arg_force_ref)
  277. PHP_FE(shell_exec, NULL)
  278. #ifdef PHP_CAN_SUPPORT_PROC_OPEN
  279. PHP_FE(proc_open, third_arg_force_ref)
  280. PHP_FE(proc_close, NULL)
  281. PHP_FE(proc_terminate, NULL)
  282. PHP_FE(proc_get_status, NULL)
  283. #endif
  284. #ifdef HAVE_NICE
  285. PHP_FE(proc_nice, NULL)
  286. #endif
  287. PHP_FE(rand, NULL)
  288. PHP_FE(srand, NULL)
  289. PHP_FE(getrandmax, NULL)
  290. PHP_FE(mt_rand, NULL)
  291. PHP_FE(mt_srand, NULL)
  292. PHP_FE(mt_getrandmax, NULL)
  293. #if HAVE_GETSERVBYNAME
  294. PHP_FE(getservbyname, NULL)
  295. #endif
  296. #if HAVE_GETSERVBYPORT
  297. PHP_FE(getservbyport, NULL)
  298. #endif
  299. #if HAVE_GETPROTOBYNAME
  300. PHP_FE(getprotobyname, NULL)
  301. #endif
  302. #if HAVE_GETPROTOBYNUMBER
  303. PHP_FE(getprotobynumber, NULL)
  304. #endif
  305. PHP_FE(getmyuid, NULL)
  306. PHP_FE(getmygid, NULL)
  307. PHP_FE(getmypid, NULL)
  308. PHP_FE(getmyinode, NULL)
  309. PHP_FE(getlastmod, NULL)
  310. PHP_FE(base64_decode, NULL)
  311. PHP_FE(base64_encode, NULL)
  312. PHP_FE(convert_uuencode, NULL)
  313. PHP_FE(convert_uudecode, NULL)
  314. PHP_FE(abs, NULL)
  315. PHP_FE(ceil, NULL)
  316. PHP_FE(floor, NULL)
  317. PHP_FE(round, NULL)
  318. PHP_FE(sin, NULL)
  319. PHP_FE(cos, NULL)
  320. PHP_FE(tan, NULL)
  321. PHP_FE(asin, NULL)
  322. PHP_FE(acos, NULL)
  323. PHP_FE(atan, NULL)
  324. PHP_FE(atan2, NULL)
  325. PHP_FE(sinh, NULL)
  326. PHP_FE(cosh, NULL)
  327. PHP_FE(tanh, NULL)
  328. #ifdef HAVE_ASINH
  329. PHP_FE(asinh, NULL)
  330. #endif
  331. #ifdef HAVE_ACOSH
  332. PHP_FE(acosh, NULL)
  333. #endif
  334. #ifdef HAVE_ATANH
  335. PHP_FE(atanh, NULL)
  336. #endif
  337. #if !defined(PHP_WIN32) && !defined(NETWARE)
  338. PHP_FE(expm1, NULL)
  339. PHP_FE(log1p, NULL)
  340. #endif
  341. PHP_FE(pi, NULL)
  342. PHP_FE(is_finite, NULL)
  343. PHP_FE(is_nan, NULL)
  344. PHP_FE(is_infinite, NULL)
  345. PHP_FE(pow, NULL)
  346. PHP_FE(exp, NULL)
  347. PHP_FE(log, NULL)
  348. PHP_FE(log10, NULL)
  349. PHP_FE(sqrt, NULL)
  350. PHP_FE(hypot, NULL)
  351. PHP_FE(deg2rad, NULL)
  352. PHP_FE(rad2deg, NULL)
  353. PHP_FE(bindec, NULL)
  354. PHP_FE(hexdec, NULL)
  355. PHP_FE(octdec, NULL)
  356. PHP_FE(decbin, NULL)
  357. PHP_FE(decoct, NULL)
  358. PHP_FE(dechex, NULL)
  359. PHP_FE(base_convert, NULL)
  360. PHP_FE(number_format, NULL)
  361. PHP_FE(fmod, NULL)
  362. PHP_FE(ip2long, NULL)
  363. PHP_FE(long2ip, NULL)
  364. PHP_FE(getenv, NULL)
  365. #ifdef HAVE_PUTENV
  366. PHP_FE(putenv, NULL)
  367. #endif
  368. #ifdef HAVE_GETOPT
  369. PHP_FE(getopt, NULL)
  370. #endif
  371. #ifdef HAVE_GETTIMEOFDAY
  372. PHP_FE(microtime, NULL)
  373. PHP_FE(gettimeofday, NULL)
  374. #endif
  375. #ifdef HAVE_GETRUSAGE
  376. PHP_FE(getrusage, NULL)
  377. #endif
  378. #ifdef HAVE_GETTIMEOFDAY
  379. PHP_FE(uniqid, NULL)
  380. #endif
  381. PHP_FE(quoted_printable_decode, NULL)
  382. PHP_FE(convert_cyr_string, NULL)
  383. PHP_FE(get_current_user, NULL)
  384. PHP_FE(set_time_limit, NULL)
  385. PHP_FE(get_cfg_var, NULL)
  386. PHP_FALIAS(magic_quotes_runtime, set_magic_quotes_runtime, NULL)
  387. PHP_FE(set_magic_quotes_runtime, NULL)
  388. PHP_FE(get_magic_quotes_gpc, NULL)
  389. PHP_FE(get_magic_quotes_runtime, NULL)
  390. PHP_FE(import_request_variables, NULL)
  391. PHP_FE(error_log, NULL)
  392. PHP_FE(call_user_func, NULL)
  393. PHP_FE(call_user_func_array, NULL)
  394. PHP_FE(call_user_method, second_arg_force_ref)
  395. PHP_FE(call_user_method_array, second_arg_force_ref)
  396. PHP_FE(serialize, NULL)
  397. PHP_FE(unserialize, NULL)
  398. PHP_FE(var_dump, NULL)
  399. PHP_FE(var_export, NULL)
  400. PHP_FE(debug_zval_dump, NULL)
  401. PHP_FE(print_r, NULL)
  402. #if MEMORY_LIMIT
  403. PHP_FE(memory_get_usage, NULL)
  404. #endif
  405. PHP_FE(register_shutdown_function, NULL)
  406. PHP_FE(register_tick_function, NULL)
  407. PHP_FE(unregister_tick_function, NULL)
  408. PHP_FE(highlight_file, NULL)
  409. PHP_FALIAS(show_source, highlight_file, NULL)
  410. PHP_FE(highlight_string, NULL)
  411. PHP_FE(php_strip_whitespace, NULL)
  412. PHP_FE(php_check_syntax, NULL)
  413. PHP_FE(ini_get, NULL)
  414. PHP_FE(ini_get_all, NULL)
  415. PHP_FE(ini_set, NULL)
  416. PHP_FALIAS(ini_alter, ini_set, NULL)
  417. PHP_FE(ini_restore, NULL)
  418. PHP_FE(get_include_path, NULL)
  419. PHP_FE(set_include_path, NULL)
  420. PHP_FE(restore_include_path, NULL)
  421. PHP_FE(setcookie, NULL)
  422. PHP_FE(setrawcookie, NULL)
  423. PHP_FE(header, NULL)
  424. PHP_FE(headers_sent, first_and_second__args_force_ref)
  425. PHP_FE(headers_list, NULL)
  426. PHP_FE(connection_aborted, NULL)
  427. PHP_FE(connection_status, NULL)
  428. PHP_FE(ignore_user_abort, NULL)
  429. PHP_FE(parse_ini_file, NULL)
  430. PHP_FE(is_uploaded_file, NULL)
  431. PHP_FE(move_uploaded_file, NULL)
  432. /* functions from dns.c */
  433. PHP_FE(gethostbyaddr, NULL)
  434. PHP_FE(gethostbyname, NULL)
  435. PHP_FE(gethostbynamel, NULL)
  436. #if HAVE_RES_SEARCH && !(defined(__BEOS__) || defined(PHP_WIN32) || defined(NETWARE))
  437. PHP_FE(dns_check_record, NULL)
  438. PHP_FALIAS(checkdnsrr, dns_check_record, NULL)
  439. # if HAVE_DN_SKIPNAME && HAVE_DN_EXPAND
  440. PHP_FE(dns_get_mx, second_and_third_args_force_ref)
  441. PHP_FALIAS(getmxrr, dns_get_mx, second_and_third_args_force_ref)
  442. # endif
  443. # if HAVE_DNS_FUNCS
  444. PHP_FE(dns_get_record, third_and_rest_force_ref)
  445. # endif
  446. #endif
  447. /* functions from type.c */
  448. PHP_FE(intval, NULL)
  449. PHP_FE(floatval, NULL)
  450. PHP_FALIAS(doubleval, floatval, NULL)
  451. PHP_FE(strval, NULL)
  452. PHP_FE(gettype, NULL)
  453. PHP_FE(settype, first_arg_force_ref)
  454. PHP_FE(is_null, NULL)
  455. PHP_FE(is_resource, NULL)
  456. PHP_FE(is_bool, NULL)
  457. PHP_FE(is_long, NULL)
  458. PHP_FE(is_float, NULL)
  459. PHP_FALIAS(is_int, is_long, NULL)
  460. PHP_FALIAS(is_integer, is_long, NULL)
  461. PHP_FALIAS(is_double, is_float, NULL)
  462. PHP_FALIAS(is_real, is_float, NULL)
  463. PHP_FE(is_numeric, NULL)
  464. PHP_FE(is_string, NULL)
  465. PHP_FE(is_array, NULL)
  466. PHP_FE(is_object, NULL)
  467. PHP_FE(is_scalar, NULL)
  468. PHP_FE(is_callable, third_arg_force_ref)
  469. /* functions from reg.c */
  470. PHP_FE(ereg, third_arg_force_ref)
  471. PHP_FE(ereg_replace, NULL)
  472. PHP_FE(eregi, third_arg_force_ref)
  473. PHP_FE(eregi_replace, NULL)
  474. PHP_FE(split, NULL)
  475. PHP_FE(spliti, NULL)
  476. PHP_FALIAS(join, implode, NULL)
  477. PHP_FE(sql_regcase, NULL)
  478. /* functions from dl.c */
  479. PHP_FE(dl, NULL)
  480. /* functions from file.c */
  481. PHP_FE(pclose, NULL)
  482. PHP_FE(popen, NULL)
  483. PHP_FE(readfile, NULL)
  484. PHP_FE(rewind, NULL)
  485. PHP_FE(rmdir, NULL)
  486. PHP_FE(umask, NULL)
  487. PHP_FE(fclose, NULL)
  488. PHP_FE(feof, NULL)
  489. PHP_FE(fgetc, NULL)
  490. PHP_FE(fgets, NULL)
  491. PHP_FE(fgetss, NULL)
  492. PHP_FE(fread, NULL)
  493. PHP_NAMED_FE(fopen, php_if_fopen, NULL)
  494. PHP_FE(fpassthru, NULL)
  495. PHP_NAMED_FE(ftruncate, php_if_ftruncate, NULL)
  496. PHP_NAMED_FE(fstat, php_if_fstat, NULL)
  497. PHP_FE(fseek, NULL)
  498. PHP_FE(ftell, NULL)
  499. PHP_FE(fflush, NULL)
  500. PHP_FE(fwrite, NULL)
  501. PHP_FALIAS(fputs, fwrite, NULL)
  502. PHP_FE(mkdir, NULL)
  503. PHP_FE(rename, NULL)
  504. PHP_FE(copy, NULL)
  505. PHP_FE(tempnam, NULL)
  506. PHP_NAMED_FE(tmpfile, php_if_tmpfile, NULL)
  507. PHP_FE(file, NULL)
  508. PHP_FE(file_get_contents, NULL)
  509. PHP_FE(file_put_contents, NULL)
  510. PHP_FE(stream_select, first_through_third_args_force_ref)
  511. PHP_FE(stream_context_create, NULL)
  512. PHP_FE(stream_context_set_params, NULL)
  513. PHP_FE(stream_context_set_option, NULL)
  514. PHP_FE(stream_context_get_options, NULL)
  515. PHP_FE(stream_filter_prepend, NULL)
  516. PHP_FE(stream_filter_append, NULL)
  517. PHP_FE(stream_socket_client, second_and_third_args_force_ref)
  518. PHP_FE(stream_socket_server, second_and_third_args_force_ref)
  519. PHP_FE(stream_socket_accept, third_arg_force_ref)
  520. PHP_FE(stream_socket_get_name, NULL)
  521. PHP_FE(stream_socket_recvfrom, fourth_arg_force_ref)
  522. PHP_FE(stream_socket_sendto, NULL)
  523. PHP_FE(stream_copy_to_stream, NULL)
  524. PHP_FE(stream_get_contents, NULL)
  525. PHP_FE(fgetcsv, NULL)
  526. PHP_FE(flock, third_arg_force_ref)
  527. PHP_FE(get_meta_tags, NULL)
  528. PHP_FE(stream_set_write_buffer, NULL)
  529. PHP_FALIAS(set_file_buffer, stream_set_write_buffer, NULL)
  530. PHP_FE(set_socket_blocking, NULL)
  531. PHP_FE(stream_set_blocking, NULL)
  532. PHP_FALIAS(socket_set_blocking, stream_set_blocking, NULL)
  533. PHP_FE(stream_get_meta_data, NULL)
  534. PHP_FE(stream_get_line, NULL)
  535. PHP_FE(stream_wrapper_register, NULL)
  536. PHP_FALIAS(stream_register_wrapper, stream_wrapper_register, NULL)
  537. PHP_FE(stream_get_wrappers, NULL)
  538. PHP_FE(stream_get_transports, NULL)
  539. PHP_FE(get_headers, NULL)
  540. #if HAVE_SYS_TIME_H || defined(PHP_WIN32)
  541. PHP_FE(stream_set_timeout, NULL)
  542. PHP_FALIAS(socket_set_timeout, stream_set_timeout, NULL)
  543. #endif
  544. PHP_FALIAS(socket_get_status, stream_get_meta_data, NULL)
  545. #if (!defined(__BEOS__) && !defined(NETWARE) && HAVE_REALPATH) || defined(ZTS)
  546. PHP_FE(realpath, NULL)
  547. #endif
  548. #ifdef HAVE_FNMATCH
  549. PHP_FE(fnmatch, NULL)
  550. #endif
  551. /* functions from fsock.c */
  552. PHP_FE(fsockopen, third_and_fourth_args_force_ref)
  553. PHP_FE(pfsockopen, third_and_fourth_args_force_ref)
  554. /* functions from pack.c */
  555. PHP_FE(pack, NULL)
  556. PHP_FE(unpack, NULL)
  557. /* functions from browscap.c */
  558. PHP_FE(get_browser, NULL)
  559. #if HAVE_CRYPT
  560. /* functions from crypt.c */
  561. PHP_FE(crypt, NULL)
  562. #endif
  563. /* functions from dir.c */
  564. PHP_FE(opendir, NULL)
  565. PHP_FE(closedir, NULL)
  566. PHP_FE(chdir, NULL)
  567. #if defined(HAVE_CHROOT) && !defined(ZTS) && ENABLE_CHROOT_FUNC
  568. PHP_FE(chroot, NULL)
  569. #endif
  570. PHP_FE(getcwd, NULL)
  571. PHP_FE(rewinddir, NULL)
  572. PHP_NAMED_FE(readdir, php_if_readdir, NULL)
  573. PHP_FALIAS(dir, getdir, NULL)
  574. PHP_FE(scandir, NULL)
  575. #ifdef HAVE_GLOB
  576. PHP_FE(glob, NULL)
  577. #endif
  578. /* functions from filestat.c */
  579. PHP_FE(fileatime, NULL)
  580. PHP_FE(filectime, NULL)
  581. PHP_FE(filegroup, NULL)
  582. PHP_FE(fileinode, NULL)
  583. PHP_FE(filemtime, NULL)
  584. PHP_FE(fileowner, NULL)
  585. PHP_FE(fileperms, NULL)
  586. PHP_FE(filesize, NULL)
  587. PHP_FE(filetype, NULL)
  588. PHP_FE(file_exists, NULL)
  589. PHP_FE(is_writable, NULL)
  590. PHP_FALIAS(is_writeable, is_writable, NULL)
  591. PHP_FE(is_readable, NULL)
  592. PHP_FE(is_executable, NULL)
  593. PHP_FE(is_file, NULL)
  594. PHP_FE(is_dir, NULL)
  595. PHP_FE(is_link, NULL)
  596. PHP_NAMED_FE(stat, php_if_stat, NULL)
  597. PHP_NAMED_FE(lstat, php_if_lstat, NULL)
  598. PHP_FE(chown, NULL)
  599. PHP_FE(chgrp, NULL)
  600. PHP_FE(chmod, NULL)
  601. #if HAVE_UTIME
  602. PHP_FE(touch, NULL)
  603. #endif
  604. PHP_FE(clearstatcache, NULL)
  605. PHP_FE(disk_total_space, NULL)
  606. PHP_FE(disk_free_space, NULL)
  607. PHP_FALIAS(diskfreespace, disk_free_space, NULL)
  608. /* functions from mail.c */
  609. #ifdef HAVE_SENDMAIL
  610. PHP_FE(mail, NULL)
  611. PHP_FE(ezmlm_hash, NULL)
  612. #endif
  613. /* functions from syslog.c */
  614. #ifdef HAVE_SYSLOG_H
  615. PHP_FE(openlog, NULL)
  616. PHP_FE(syslog, NULL)
  617. PHP_FE(closelog, NULL)
  618. PHP_FE(define_syslog_variables, NULL)
  619. #endif
  620. /* functions from lcg.c */
  621. PHP_FE(lcg_value, NULL)
  622. /* functions from metaphone.c */
  623. PHP_FE(metaphone, NULL)
  624. /* functions from output.c */
  625. PHP_FE(ob_start, NULL)
  626. PHP_FE(ob_flush, NULL)
  627. PHP_FE(ob_clean, NULL)
  628. PHP_FE(ob_end_flush, NULL)
  629. PHP_FE(ob_end_clean, NULL)
  630. PHP_FE(ob_get_flush, NULL)
  631. PHP_FE(ob_get_clean, NULL)
  632. PHP_FE(ob_get_length, NULL)
  633. PHP_FE(ob_get_level, NULL)
  634. PHP_FE(ob_get_status, NULL)
  635. PHP_FE(ob_get_contents, NULL)
  636. PHP_FE(ob_implicit_flush, NULL)
  637. PHP_FE(ob_list_handlers, NULL)
  638. /* functions from array.c */
  639. PHP_FE(ksort, first_arg_force_ref)
  640. PHP_FE(krsort, first_arg_force_ref)
  641. PHP_FE(natsort, first_arg_force_ref)
  642. PHP_FE(natcasesort, first_arg_force_ref)
  643. PHP_FE(asort, first_arg_force_ref)
  644. PHP_FE(arsort, first_arg_force_ref)
  645. PHP_FE(sort, first_arg_force_ref)
  646. PHP_FE(rsort, first_arg_force_ref)
  647. PHP_FE(usort, first_arg_force_ref)
  648. PHP_FE(uasort, first_arg_force_ref)
  649. PHP_FE(uksort, first_arg_force_ref)
  650. PHP_FE(shuffle, first_arg_force_ref)
  651. PHP_FE(array_walk, first_arg_force_ref)
  652. PHP_FE(array_walk_recursive, first_arg_force_ref)
  653. PHP_FE(count, NULL)
  654. PHP_FE(end, first_arg_force_ref)
  655. PHP_FE(prev, first_arg_force_ref)
  656. PHP_FE(next, first_arg_force_ref)
  657. PHP_FE(reset, first_arg_force_ref)
  658. PHP_FE(current, first_arg_force_ref)
  659. PHP_FE(key, first_arg_force_ref)
  660. PHP_FE(min, NULL)
  661. PHP_FE(max, NULL)
  662. PHP_FE(in_array, NULL)
  663. PHP_FE(array_search, NULL)
  664. PHP_FE(extract, NULL)
  665. PHP_FE(compact, NULL)
  666. PHP_FE(array_fill, NULL)
  667. PHP_FE(range, NULL)
  668. PHP_FE(array_multisort, NULL)
  669. PHP_FE(array_push, first_arg_force_ref)
  670. PHP_FE(array_pop, first_arg_force_ref)
  671. PHP_FE(array_shift, first_arg_force_ref)
  672. PHP_FE(array_unshift, first_arg_force_ref)
  673. PHP_FE(array_splice, first_arg_force_ref)
  674. PHP_FE(array_slice, NULL)
  675. PHP_FE(array_merge, NULL)
  676. PHP_FE(array_merge_recursive, NULL)
  677. PHP_FE(array_keys, NULL)
  678. PHP_FE(array_values, NULL)
  679. PHP_FE(array_count_values, NULL)
  680. PHP_FE(array_reverse, NULL)
  681. PHP_FE(array_reduce, NULL)
  682. PHP_FE(array_pad, NULL)
  683. PHP_FE(array_flip, NULL)
  684. PHP_FE(array_change_key_case, NULL)
  685. PHP_FE(array_rand, NULL)
  686. PHP_FE(array_unique, NULL)
  687. PHP_FE(array_intersect, NULL)
  688. PHP_FE(array_uintersect, NULL)
  689. PHP_FE(array_intersect_assoc, NULL)
  690. PHP_FE(array_uintersect_assoc, NULL)
  691. PHP_FE(array_intersect_uassoc, NULL)
  692. PHP_FE(array_uintersect_uassoc, NULL)
  693. PHP_FE(array_diff, NULL)
  694. PHP_FE(array_udiff, NULL)
  695. PHP_FE(array_diff_assoc, NULL)
  696. PHP_FE(array_udiff_assoc, NULL)
  697. PHP_FE(array_diff_uassoc, NULL)
  698. PHP_FE(array_udiff_uassoc, NULL)
  699. PHP_FE(array_sum, NULL)
  700. PHP_FE(array_filter, NULL)
  701. PHP_FE(array_map, NULL)
  702. PHP_FE(array_chunk, NULL)
  703. PHP_FE(array_combine, NULL)
  704. PHP_FE(array_key_exists, NULL)
  705. /* aliases from array.c */
  706. PHP_FALIAS(pos, current, first_arg_force_ref)
  707. PHP_FALIAS(sizeof, count, NULL)
  708. PHP_FALIAS(key_exists, array_key_exists, NULL)
  709. /* functions from assert.c */
  710. PHP_FE(assert, NULL)
  711. PHP_FE(assert_options, NULL)
  712. /* functions from versioning.c */
  713. PHP_FE(version_compare, NULL)
  714. /* functions from ftok.c*/
  715. #if HAVE_FTOK
  716. PHP_FE(ftok, NULL)
  717. #endif
  718. PHP_FE(str_rot13, NULL)
  719. PHP_FE(stream_get_filters, NULL)
  720. PHP_FE(stream_filter_register, NULL)
  721. PHP_FE(stream_bucket_make_writeable, NULL)
  722. PHP_FE(stream_bucket_prepend, NULL)
  723. PHP_FE(stream_bucket_append, NULL)
  724. PHP_FE(stream_bucket_new, NULL)
  725. PHP_FE(output_add_rewrite_var, NULL)
  726. PHP_FE(output_reset_rewrite_vars, NULL)
  727. PHP_FE(date_sunrise, NULL)
  728. PHP_FE(date_sunset, NULL)
  729. {NULL, NULL, NULL}
  730. };
  731. static PHP_INI_MH(OnUpdateSafeModeProtectedEnvVars)
  732. {
  733. char *protected_vars, *protected_var;
  734. char *token_buf;
  735. int dummy = 1;
  736. protected_vars = estrndup(new_value, new_value_length);
  737. zend_hash_clean(&BG(sm_protected_env_vars));
  738. protected_var = php_strtok_r(protected_vars, ", ", &token_buf);
  739. while (protected_var) {
  740. zend_hash_update(&BG(sm_protected_env_vars), protected_var, strlen(protected_var), &dummy, sizeof(int), NULL);
  741. protected_var = php_strtok_r(NULL, ", ", &token_buf);
  742. }
  743. efree(protected_vars);
  744. return SUCCESS;
  745. }
  746. static PHP_INI_MH(OnUpdateSafeModeAllowedEnvVars)
  747. {
  748. if (BG(sm_allowed_env_vars)) {
  749. free(BG(sm_allowed_env_vars));
  750. }
  751. BG(sm_allowed_env_vars) = zend_strndup(new_value, new_value_length);
  752. return SUCCESS;
  753. }
  754. PHP_INI_BEGIN()
  755. PHP_INI_ENTRY_EX("safe_mode_protected_env_vars", SAFE_MODE_PROTECTED_ENV_VARS, PHP_INI_SYSTEM, OnUpdateSafeModeProtectedEnvVars, NULL)
  756. PHP_INI_ENTRY_EX("safe_mode_allowed_env_vars", SAFE_MODE_ALLOWED_ENV_VARS, PHP_INI_SYSTEM, OnUpdateSafeModeAllowedEnvVars, NULL)
  757. PHP_INI_ENTRY("date.default_latitude", DATE_DEFAULT_LATITUDE, PHP_INI_ALL, NULL)
  758. PHP_INI_ENTRY("date.default_longitude", DATE_DEFAULT_LONGITUDE, PHP_INI_ALL, NULL)
  759. PHP_INI_ENTRY("date.sunset_zenith", DATE_SUNSET_ZENITH, PHP_INI_ALL, NULL)
  760. PHP_INI_ENTRY("date.sunrise_zenith", DATE_SUNRISE_ZENITH, PHP_INI_ALL, NULL)
  761. PHP_INI_END()
  762. zend_module_entry basic_functions_module = {
  763. STANDARD_MODULE_HEADER,
  764. "standard", /* extension name */
  765. basic_functions, /* function list */
  766. PHP_MINIT(basic), /* process startup */
  767. PHP_MSHUTDOWN(basic), /* process shutdown */
  768. PHP_RINIT(basic), /* request startup */
  769. PHP_RSHUTDOWN(basic), /* request shutdown */
  770. PHP_MINFO(basic), /* extension info */
  771. PHP_VERSION, /* extension version */
  772. STANDARD_MODULE_PROPERTIES
  773. };
  774. #if defined(HAVE_PUTENV)
  775. static void php_putenv_destructor(putenv_entry *pe)
  776. {
  777. if (pe->previous_value) {
  778. #if _MSC_VER >= 1300
  779. /* VS.Net has a bug in putenv() when setting a variable that
  780. * is already set; if the SetEnvironmentVariable() API call
  781. * fails, the Crt will double free() a string.
  782. * We try to avoid this by setting our own value first */
  783. SetEnvironmentVariable(pe->key, "bugbug");
  784. #endif
  785. putenv(pe->previous_value);
  786. } else {
  787. # if HAVE_UNSETENV
  788. unsetenv(pe->key);
  789. # elif defined(PHP_WIN32)
  790. SetEnvironmentVariable(pe->key, NULL);
  791. # else
  792. char **env;
  793. for (env = environ; env != NULL && *env != NULL; env++) {
  794. if (!strncmp(*env, pe->key, pe->key_len) && (*env)[pe->key_len] == '=') { /* found it */
  795. *env = "";
  796. break;
  797. }
  798. }
  799. # endif
  800. }
  801. #ifdef HAVE_TZSET
  802. /* don't forget to reset the various libc globals that
  803. * we might have changed by an earlier call to tzset(). */
  804. if (!strncmp(pe->key, "TZ", pe->key_len)) {
  805. tzset();
  806. }
  807. #endif
  808. efree(pe->putenv_string);
  809. efree(pe->key);
  810. }
  811. #endif
  812. static void basic_globals_ctor(php_basic_globals *basic_globals_p TSRMLS_DC)
  813. {
  814. BG(rand_is_seeded) = 0;
  815. BG(mt_rand_is_seeded) = 0;
  816. BG(next) = NULL;
  817. BG(left) = -1;
  818. BG(user_tick_functions) = NULL;
  819. BG(user_filter_map) = NULL;
  820. BG(user_compare_fci_cache) = empty_fcall_info_cache;
  821. /*BG(array_walk_fci_cache) = empty_fcall_info_cache;*/
  822. zend_hash_init(&BG(sm_protected_env_vars), 5, NULL, NULL, 1);
  823. BG(sm_allowed_env_vars) = NULL;
  824. memset(&BG(url_adapt_state), 0, sizeof(BG(url_adapt_state)));
  825. memset(&BG(url_adapt_state_ex), 0, sizeof(BG(url_adapt_state_ex)));
  826. BG(incomplete_class) = php_create_incomplete_class(TSRMLS_C);
  827. }
  828. static void basic_globals_dtor(php_basic_globals *basic_globals_p TSRMLS_DC)
  829. {
  830. zend_hash_destroy(&BG(sm_protected_env_vars));
  831. if (BG(sm_allowed_env_vars)) {
  832. free(BG(sm_allowed_env_vars));
  833. }
  834. if (BG(url_adapt_state_ex).tags) {
  835. zend_hash_destroy(BG(url_adapt_state_ex).tags);
  836. free(BG(url_adapt_state_ex).tags);
  837. }
  838. }
  839. #define PHP_DOUBLE_INFINITY_HIGH 0x7ff00000
  840. #define PHP_DOUBLE_QUIET_NAN_HIGH 0xfff80000
  841. PHPAPI double php_get_nan(void)
  842. {
  843. #if HAVE_HUGE_VAL_NAN
  844. return HUGE_VAL + -HUGE_VAL;
  845. #elif defined(__i386__) || defined(_X86_) || defined(ALPHA) || defined(_ALPHA) || defined(__alpha)
  846. double val = 0.0;
  847. ((php_uint32*)&val)[1] = PHP_DOUBLE_QUIET_NAN_HIGH;
  848. ((php_uint32*)&val)[0] = 0;
  849. return val;
  850. #elif HAVE_ATOF_ACCEPTS_NAN
  851. return atof("NAN");
  852. #else
  853. return 0.0/0.0;
  854. #endif
  855. }
  856. PHPAPI double php_get_inf(void)
  857. {
  858. #if HAVE_HUGE_VAL_INF
  859. return HUGE_VAL;
  860. #elif defined(__i386__) || defined(_X86_) || defined(ALPHA) || defined(_ALPHA) || defined(__alpha)
  861. double val = 0.0;
  862. ((php_uint32*)&val)[1] = PHP_DOUBLE_INFINITY_HIGH;
  863. ((php_uint32*)&val)[0] = 0;
  864. return val;
  865. #elif HAVE_ATOF_ACCEPTS_INF
  866. return atof("INF");
  867. #else
  868. return 1.0/0.0;
  869. #endif
  870. }
  871. PHP_MINIT_FUNCTION(basic)
  872. {
  873. #ifdef ZTS
  874. ts_allocate_id(&basic_globals_id, sizeof(php_basic_globals), (ts_allocate_ctor) basic_globals_ctor, (ts_allocate_dtor) basic_globals_dtor);
  875. #else
  876. basic_globals_ctor(&basic_globals TSRMLS_CC);
  877. #endif
  878. REGISTER_LONG_CONSTANT("CONNECTION_ABORTED", PHP_CONNECTION_ABORTED, CONST_CS | CONST_PERSISTENT);
  879. REGISTER_LONG_CONSTANT("CONNECTION_NORMAL", PHP_CONNECTION_NORMAL, CONST_CS | CONST_PERSISTENT);
  880. REGISTER_LONG_CONSTANT("CONNECTION_TIMEOUT", PHP_CONNECTION_TIMEOUT, CONST_CS | CONST_PERSISTENT);
  881. REGISTER_LONG_CONSTANT("INI_USER", ZEND_INI_USER, CONST_CS | CONST_PERSISTENT);
  882. REGISTER_LONG_CONSTANT("INI_PERDIR", ZEND_INI_PERDIR, CONST_CS | CONST_PERSISTENT);
  883. REGISTER_LONG_CONSTANT("INI_SYSTEM", ZEND_INI_SYSTEM, CONST_CS | CONST_PERSISTENT);
  884. REGISTER_LONG_CONSTANT("INI_ALL", ZEND_INI_ALL, CONST_CS | CONST_PERSISTENT);
  885. REGISTER_LONG_CONSTANT("SUNFUNCS_RET_TIMESTAMP", SUNFUNCS_RET_TIMESTAMP, CONST_CS | CONST_PERSISTENT);
  886. REGISTER_LONG_CONSTANT("SUNFUNCS_RET_STRING", SUNFUNCS_RET_STRING, CONST_CS | CONST_PERSISTENT);
  887. REGISTER_LONG_CONSTANT("SUNFUNCS_RET_DOUBLE", SUNFUNCS_RET_DOUBLE, CONST_CS | CONST_PERSISTENT);
  888. #define REGISTER_MATH_CONSTANT(x) REGISTER_DOUBLE_CONSTANT(#x, x, CONST_CS | CONST_PERSISTENT)
  889. REGISTER_MATH_CONSTANT(M_E);
  890. REGISTER_MATH_CONSTANT(M_LOG2E);
  891. REGISTER_MATH_CONSTANT(M_LOG10E);
  892. REGISTER_MATH_CONSTANT(M_LN2);
  893. REGISTER_MATH_CONSTANT(M_LN10);
  894. REGISTER_MATH_CONSTANT(M_PI);
  895. REGISTER_MATH_CONSTANT(M_PI_2);
  896. REGISTER_MATH_CONSTANT(M_PI_4);
  897. REGISTER_MATH_CONSTANT(M_1_PI);
  898. REGISTER_MATH_CONSTANT(M_2_PI);
  899. REGISTER_MATH_CONSTANT(M_2_SQRTPI);
  900. REGISTER_MATH_CONSTANT(M_SQRT2);
  901. REGISTER_MATH_CONSTANT(M_SQRT1_2);
  902. REGISTER_DOUBLE_CONSTANT("INF", php_get_inf(), CONST_CS | CONST_PERSISTENT);
  903. REGISTER_DOUBLE_CONSTANT("NAN", php_get_nan(), CONST_CS | CONST_PERSISTENT);
  904. #if ENABLE_TEST_CLASS
  905. test_class_startup();
  906. #endif
  907. REGISTER_INI_ENTRIES();
  908. register_phpinfo_constants(INIT_FUNC_ARGS_PASSTHRU);
  909. register_html_constants(INIT_FUNC_ARGS_PASSTHRU);
  910. register_string_constants(INIT_FUNC_ARGS_PASSTHRU);
  911. PHP_MINIT(regex)(INIT_FUNC_ARGS_PASSTHRU);
  912. PHP_MINIT(file)(INIT_FUNC_ARGS_PASSTHRU);
  913. PHP_MINIT(pack)(INIT_FUNC_ARGS_PASSTHRU);
  914. PHP_MINIT(browscap)(INIT_FUNC_ARGS_PASSTHRU);
  915. PHP_MINIT(standard_filters)(INIT_FUNC_ARGS_PASSTHRU);
  916. PHP_MINIT(user_filters)(INIT_FUNC_ARGS_PASSTHRU);
  917. #if defined(HAVE_LOCALECONV) && defined(ZTS)
  918. PHP_MINIT(localeconv)(INIT_FUNC_ARGS_PASSTHRU);
  919. #endif
  920. #if defined(HAVE_NL_LANGINFO)
  921. PHP_MINIT(nl_langinfo)(INIT_FUNC_ARGS_PASSTHRU);
  922. #endif
  923. #if HAVE_CRYPT
  924. PHP_MINIT(crypt)(INIT_FUNC_ARGS_PASSTHRU);
  925. #endif
  926. PHP_MINIT(lcg)(INIT_FUNC_ARGS_PASSTHRU);
  927. PHP_MINIT(dir)(INIT_FUNC_ARGS_PASSTHRU);
  928. #ifdef HAVE_SYSLOG_H
  929. PHP_MINIT(syslog)(INIT_FUNC_ARGS_PASSTHRU);
  930. #endif
  931. PHP_MINIT(array)(INIT_FUNC_ARGS_PASSTHRU);
  932. PHP_MINIT(assert)(INIT_FUNC_ARGS_PASSTHRU);
  933. PHP_MINIT(url_scanner_ex)(INIT_FUNC_ARGS_PASSTHRU);
  934. #ifdef PHP_CAN_SUPPORT_PROC_OPEN
  935. PHP_MINIT(proc_open)(INIT_FUNC_ARGS_PASSTHRU);
  936. #endif
  937. PHP_MINIT(user_streams)(INIT_FUNC_ARGS_PASSTHRU);
  938. PHP_MINIT(imagetypes)(INIT_FUNC_ARGS_PASSTHRU);
  939. php_register_url_stream_wrapper("php", &php_stream_php_wrapper TSRMLS_CC);
  940. php_register_url_stream_wrapper("file", &php_plain_files_wrapper TSRMLS_CC);
  941. #ifndef PHP_CURL_URL_WRAPPERS
  942. php_register_url_stream_wrapper("http", &php_stream_http_wrapper TSRMLS_CC);
  943. php_register_url_stream_wrapper("ftp", &php_stream_ftp_wrapper TSRMLS_CC);
  944. #endif
  945. #if HAVE_RES_SEARCH && !(defined(__BEOS__)||defined(PHP_WIN32) || defined(NETWARE))
  946. # if HAVE_DNS_FUNCS
  947. PHP_MINIT(dns)(INIT_FUNC_ARGS_PASSTHRU);
  948. # endif
  949. #endif
  950. return SUCCESS;
  951. }
  952. PHP_MSHUTDOWN_FUNCTION(basic)
  953. {
  954. #ifdef ZTS
  955. ts_free_id(basic_globals_id);
  956. #else
  957. basic_globals_dtor(&basic_globals TSRMLS_CC);
  958. #endif
  959. php_unregister_url_stream_wrapper("php" TSRMLS_CC);
  960. #ifndef PHP_CURL_URL_WRAPPERS
  961. php_unregister_url_stream_wrapper("http" TSRMLS_CC);
  962. php_unregister_url_stream_wrapper("ftp" TSRMLS_CC);
  963. #endif
  964. UNREGISTER_INI_ENTRIES();
  965. PHP_MSHUTDOWN(regex)(SHUTDOWN_FUNC_ARGS_PASSTHRU);
  966. PHP_MSHUTDOWN(browscap)(SHUTDOWN_FUNC_ARGS_PASSTHRU);
  967. PHP_MSHUTDOWN(array)(SHUTDOWN_FUNC_ARGS_PASSTHRU);
  968. PHP_MSHUTDOWN(assert)(SHUTDOWN_FUNC_ARGS_PASSTHRU);
  969. PHP_MSHUTDOWN(url_scanner_ex)(SHUTDOWN_FUNC_ARGS_PASSTHRU);
  970. PHP_MSHUTDOWN(file)(SHUTDOWN_FUNC_ARGS_PASSTHRU);
  971. PHP_MSHUTDOWN(standard_filters)(SHUTDOWN_FUNC_ARGS_PASSTHRU);
  972. #if defined(HAVE_LOCALECONV) && defined(ZTS)
  973. PHP_MSHUTDOWN(localeconv)(SHUTDOWN_FUNC_ARGS_PASSTHRU);
  974. #endif
  975. return SUCCESS;
  976. }
  977. PHP_RINIT_FUNCTION(basic)
  978. {
  979. memset(BG(strtok_table), 0, 256);
  980. BG(strtok_string) = NULL;
  981. BG(strtok_zval) = NULL;
  982. BG(locale_string) = NULL;
  983. BG(user_compare_func_name) = NULL;
  984. BG(array_walk_func_name) = NULL;
  985. BG(page_uid) = -1;
  986. BG(page_gid) = -1;
  987. BG(page_inode) = -1;
  988. BG(page_mtime) = -1;
  989. #ifdef HAVE_PUTENV
  990. if (zend_hash_init(&BG(putenv_ht), 1, NULL, (void (*)(void *)) php_putenv_destructor, 0) == FAILURE) {
  991. return FAILURE;
  992. }
  993. #endif
  994. BG(user_shutdown_function_names) = NULL;
  995. PHP_RINIT(lcg)(INIT_FUNC_ARGS_PASSTHRU);
  996. PHP_RINIT(filestat)(INIT_FUNC_ARGS_PASSTHRU);
  997. #ifdef HAVE_SYSLOG_H
  998. PHP_RINIT(syslog)(INIT_FUNC_ARGS_PASSTHRU);
  999. #endif
  1000. PHP_RINIT(dir)(INIT_FUNC_ARGS_PASSTHRU);
  1001. PHP_RINIT(url_scanner_ex)(INIT_FUNC_ARGS_PASSTHRU);
  1002. /* Reset magic_quotes_runtime */
  1003. PG(magic_quotes_runtime) = INI_BOOL("magic_quotes_runtime");
  1004. /* Setup default context */
  1005. FG(default_context) = NULL;
  1006. return SUCCESS;
  1007. }
  1008. PHP_RSHUTDOWN_FUNCTION(basic)
  1009. {
  1010. if (BG(strtok_zval)) {
  1011. zval_ptr_dtor(&BG(strtok_zval));
  1012. }
  1013. BG(strtok_string) = NULL;
  1014. BG(strtok_zval) = NULL;
  1015. #ifdef HAVE_PUTENV
  1016. zend_hash_destroy(&BG(putenv_ht));
  1017. #endif
  1018. /* Check if locale was changed and change it back
  1019. to the value in startup environment */
  1020. if (BG(locale_string) != NULL) {
  1021. setlocale(LC_ALL, "C");
  1022. setlocale(LC_CTYPE, "");
  1023. }
  1024. STR_FREE(BG(locale_string));
  1025. PHP_RSHUTDOWN(filestat)(SHUTDOWN_FUNC_ARGS_PASSTHRU);
  1026. #ifdef HAVE_SYSLOG_H
  1027. PHP_RSHUTDOWN(syslog)(SHUTDOWN_FUNC_ARGS_PASSTHRU);
  1028. #endif
  1029. PHP_RSHUTDOWN(assert)(SHUTDOWN_FUNC_ARGS_PASSTHRU);
  1030. PHP_RSHUTDOWN(url_scanner_ex)(SHUTDOWN_FUNC_ARGS_PASSTHRU);
  1031. PHP_RSHUTDOWN(streams)(SHUTDOWN_FUNC_ARGS_PASSTHRU);
  1032. if (BG(user_tick_functions)) {
  1033. zend_llist_destroy(BG(user_tick_functions));
  1034. efree(BG(user_tick_functions));
  1035. BG(user_tick_functions) = NULL;
  1036. }
  1037. PHP_RSHUTDOWN(user_filters)(SHUTDOWN_FUNC_ARGS_PASSTHRU);
  1038. return SUCCESS;
  1039. }
  1040. PHP_MINFO_FUNCTION(basic)
  1041. {
  1042. php_info_print_table_start();
  1043. PHP_MINFO(regex)(ZEND_MODULE_INFO_FUNC_ARGS_PASSTHRU);
  1044. PHP_MINFO(dl)(ZEND_MODULE_INFO_FUNC_ARGS_PASSTHRU);
  1045. PHP_MINFO(mail)(ZEND_MODULE_INFO_FUNC_ARGS_PASSTHRU);
  1046. php_info_print_table_end();
  1047. PHP_MINFO(assert)(ZEND_MODULE_INFO_FUNC_ARGS_PASSTHRU);
  1048. }
  1049. /* {{{ proto mixed constant(string const_name)
  1050. Given the name of a constant this function will return the constants associated value */
  1051. PHP_FUNCTION(constant)
  1052. {
  1053. zval **const_name;
  1054. if (ZEND_NUM_ARGS() != 1 ||
  1055. zend_get_parameters_ex(1, &const_name) == FAILURE) {
  1056. WRONG_PARAM_COUNT;
  1057. }
  1058. convert_to_string_ex(const_name);
  1059. if (!zend_get_constant(Z_STRVAL_PP(const_name), Z_STRLEN_PP(const_name), return_value TSRMLS_CC)) {
  1060. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't find constant %s", Z_STRVAL_PP(const_name));
  1061. RETURN_NULL();
  1062. }
  1063. }
  1064. /* }}} */
  1065. /* {{{ proto int ip2long(string ip_address)
  1066. Converts a string containing an (IPv4) Internet Protocol dotted address into a proper address */
  1067. PHP_FUNCTION(ip2long)
  1068. {
  1069. zval **str;
  1070. unsigned long int ip;
  1071. if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) {
  1072. WRONG_PARAM_COUNT;
  1073. }
  1074. convert_to_string_ex(str);
  1075. if (Z_STRLEN_PP(str) == 0 || (ip = inet_addr(Z_STRVAL_PP(str))) == INADDR_NONE) {
  1076. RETURN_LONG(-1);
  1077. }
  1078. RETURN_LONG(ntohl(ip));
  1079. }
  1080. /* }}} */
  1081. /* {{{ proto string long2ip(int proper_address)
  1082. Converts an (IPv4) Internet network address into a string in Internet standard dotted format */
  1083. PHP_FUNCTION(long2ip)
  1084. {
  1085. zval **num;
  1086. unsigned long n;
  1087. struct in_addr myaddr;
  1088. if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) {
  1089. WRONG_PARAM_COUNT;
  1090. }
  1091. convert_to_string_ex(num);
  1092. n = strtoul(Z_STRVAL_PP(num), NULL, 0);
  1093. myaddr.s_addr = htonl(n);
  1094. RETURN_STRING(inet_ntoa(myaddr), 1);
  1095. }
  1096. /* }}} */
  1097. /********************
  1098. * System Functions *
  1099. ********************/
  1100. /* {{{ proto string getenv(string varname)
  1101. Get the value of an environment variable */
  1102. PHP_FUNCTION(getenv)
  1103. {
  1104. char *ptr, *str;
  1105. int str_len;
  1106. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) {
  1107. RETURN_FALSE;
  1108. }
  1109. ptr = sapi_getenv(str, str_len TSRMLS_CC);
  1110. if (! ptr) {
  1111. ptr = getenv(str);
  1112. }
  1113. if (ptr) {
  1114. RETURN_STRING(ptr, 1);
  1115. }
  1116. RETURN_FALSE;
  1117. }
  1118. /* }}} */
  1119. #ifdef HAVE_PUTENV
  1120. /* {{{ proto bool putenv(string setting)
  1121. Set the value of an environment variable */
  1122. PHP_FUNCTION(putenv)
  1123. {
  1124. pval **str;
  1125. if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) {
  1126. WRONG_PARAM_COUNT;
  1127. }
  1128. convert_to_string_ex(str);
  1129. if (Z_STRVAL_PP(str) && *(Z_STRVAL_PP(str))) {
  1130. char *p, **env;
  1131. putenv_entry pe;
  1132. pe.putenv_string = estrndup(Z_STRVAL_PP(str), Z_STRLEN_PP(str));
  1133. pe.key = estrndup(Z_STRVAL_PP(str), Z_STRLEN_PP(str));
  1134. if ((p = strchr(pe.key, '='))) { /* nullify the '=' if there is one */
  1135. *p = '\0';
  1136. }
  1137. pe.key_len = strlen(pe.key);
  1138. if (PG(safe_mode)) {
  1139. /* Check the protected list */
  1140. if (zend_hash_exists(&BG(sm_protected_env_vars), pe.key, pe.key_len)) {
  1141. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Safe Mode warning: Cannot override protected environment variable '%s'", pe.key);
  1142. efree(pe.putenv_string);
  1143. efree(pe.key);
  1144. RETURN_FALSE;
  1145. }
  1146. /* Check the allowed list */
  1147. if (BG(sm_allowed_env_vars) && *BG(sm_allowed_env_vars)) {
  1148. char *allowed_env_vars = estrdup(BG(sm_allowed_env_vars));
  1149. char *allowed_prefix = strtok(allowed_env_vars, ", ");
  1150. zend_bool allowed = 0;
  1151. while (allowed_prefix) {
  1152. if (!strncmp(allowed_prefix, pe.key, strlen(allowed_prefix))) {
  1153. allowed = 1;
  1154. break;
  1155. }
  1156. allowed_prefix = strtok(NULL, ", ");
  1157. }
  1158. efree(allowed_env_vars);
  1159. if (!allowed) {
  1160. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Safe Mode warning: Cannot set environment variable '%s' - it's not in the allowed list", pe.key);
  1161. efree(pe.putenv_string);
  1162. efree(pe.key);
  1163. RETURN_FALSE;
  1164. }
  1165. }
  1166. }
  1167. zend_hash_del(&BG(putenv_ht), pe.key, pe.key_len+1);
  1168. /* find previous value */
  1169. pe.previous_value = NULL;
  1170. for (env = environ; env != NULL && *env != NULL; env++) {
  1171. if (!strncmp(*env, pe.key, pe.key_len) && (*env)[pe.key_len] == '=') { /* found it */
  1172. pe.previous_value = *env;
  1173. break;
  1174. }
  1175. }
  1176. #if _MSC_VER >= 1300
  1177. /* VS.Net has a bug in putenv() when setting a variable that
  1178. * is already set; if the SetEnvironmentVariable() API call
  1179. * fails, the Crt will double free() a string.
  1180. * We try to avoid this by setting our own value first */
  1181. SetEnvironmentVariable(pe.key, "bugbug");
  1182. #endif
  1183. if (putenv(pe.putenv_string) == 0) { /* success */
  1184. zend_hash_add(&BG(putenv_ht), pe.key, pe.key_len+1, (void **) &pe, sizeof(putenv_entry), NULL);
  1185. #ifdef HAVE_TZSET
  1186. if (!strncmp(pe.key, "TZ", pe.key_len)) {
  1187. tzset();
  1188. }
  1189. #endif
  1190. RETURN_TRUE;
  1191. } else {
  1192. efree(pe.putenv_string);
  1193. efree(pe.key);
  1194. RETURN_FALSE;
  1195. }
  1196. }
  1197. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid parameter syntax.");
  1198. RETURN_FALSE;
  1199. }
  1200. /* }}} */
  1201. #endif
  1202. #ifdef HAVE_GETOPT
  1203. /* {{{ free_argv
  1204. Free the memory allocated to an argv array. */
  1205. static void free_argv(char **argv, int argc)
  1206. {
  1207. int i;
  1208. if (argv) {
  1209. for (i = 0; i < argc; i++) {
  1210. if (argv[i]) {
  1211. efree(argv[i]);
  1212. }
  1213. }
  1214. efree(argv);
  1215. }
  1216. }
  1217. /* }}} */
  1218. #ifdef HARTMUT_0
  1219. /* {{{ free_longopts
  1220. Free the memory allocated to an longopt array. */
  1221. static void free_longopts(struct option *longopts)
  1222. {
  1223. struct option *p;
  1224. if(longopts) {
  1225. for(p=longopts; p->name; p++) {
  1226. efree((char *)(p->name));
  1227. }
  1228. efree(longopts);
  1229. }
  1230. }
  1231. /* }}} */
  1232. #endif
  1233. /* {{{ proto array getopt(string options [, array longopts])
  1234. Get options from the command line argument list */
  1235. PHP_FUNCTION(getopt)
  1236. {
  1237. char *options = NULL, **argv = NULL;
  1238. char opt[2] = { '\0' };
  1239. char *optname;
  1240. int argc = 0, options_len = 0, o;
  1241. zval *val, **args = NULL, *p_longopts = NULL;
  1242. #ifdef HARTMUT_0
  1243. struct option *longopts = NULL;
  1244. int longindex = 0;
  1245. #endif
  1246. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|a",
  1247. &options, &options_len, &p_longopts) == FAILURE) {
  1248. RETURN_FALSE;
  1249. }
  1250. /*
  1251. * Get argv from the global symbol table. We calculate argc ourselves
  1252. * in order to be on the safe side, even though it is also available
  1253. * from the symbol table.
  1254. */
  1255. if (zend_hash_find(HASH_OF(PG(http_globals)[TRACK_VARS_SERVER]), "argv", sizeof("argv"), (void **) &args) != FAILURE ||
  1256. zend_hash_find(&EG(symbol_table), "argv", sizeof("argv"), (void **) &args) != FAILURE) {
  1257. int pos = 0;
  1258. zval **arg;
  1259. argc = zend_hash_num_elements(Z_ARRVAL_PP(args));
  1260. /*
  1261. * Attempt to allocate enough memory to hold all of the arguments
  1262. * and a trailing NULL
  1263. */
  1264. if ((argv = (char **) safe_emalloc(sizeof(char *), (argc + 1), 0)) == NULL) {
  1265. RETURN_FALSE;
  1266. }
  1267. /* Reset the array indexes. */
  1268. zend_hash_internal_pointer_reset(Z_ARRVAL_PP(args));
  1269. /* Iterate over the hash to construct the argv array. */
  1270. while (zend_hash_get_current_data(Z_ARRVAL_PP(args),
  1271. (void **)&arg) == SUCCESS) {
  1272. argv[pos++] = estrdup(Z_STRVAL_PP(arg));
  1273. zend_hash_move_forward(Z_ARRVAL_PP(args));
  1274. }
  1275. /*
  1276. * The C Standard requires argv[argc] to be NULL - this might
  1277. * keep some getopt implementations happy.
  1278. */
  1279. argv[argc] = NULL;
  1280. } else {
  1281. /* Return false if we can't find argv. */
  1282. RETURN_FALSE;
  1283. }
  1284. if(p_longopts) {
  1285. #ifdef HARTMUT_0
  1286. int len, c = zend_hash_num_elements(Z_ARRVAL_P(p_longopts));
  1287. struct option *p;
  1288. zval **arg;
  1289. char *name;
  1290. longopts = (struct option *)ecalloc(c+1, sizeof(struct option));
  1291. if(!longopts) RETURN_FALSE;
  1292. /* Reset the array indexes. */
  1293. zend_hash_internal_pointer_reset(Z_ARRVAL_P(p_longopts));
  1294. p = longopts;
  1295. /* Iterate over the hash to construct the argv array. */
  1296. while (zend_hash_get_current_data(Z_ARRVAL_P(p_longopts),
  1297. (void **)&arg) == SUCCESS) {
  1298. p->has_arg = 0;
  1299. name = estrdup(Z_STRVAL_PP(arg));
  1300. len = strlen(name);
  1301. if((len > 0) && (name[len-1] == ':')) {
  1302. p->has_arg++;
  1303. name[len-1] = '\0';
  1304. if((len > 1) && (name[len-2] == ':')) {
  1305. p->has_arg++;
  1306. name[len-2] = '\0';
  1307. }
  1308. }
  1309. p->name = name;
  1310. p->flag = NULL;
  1311. p->val = 0;
  1312. zend_hash_move_forward(Z_ARRVAL_P(p_longopts));
  1313. p++;
  1314. }
  1315. #else
  1316. php_error_docref(NULL TSRMLS_CC, E_WARNING, "No support for long options in this build");
  1317. #endif
  1318. }
  1319. /* Initialize the return value as an array. */
  1320. array_init(return_value);
  1321. /* Disable getopt()'s error messages. */
  1322. opterr = 0;
  1323. /* Invoke getopt(3) on the argument array. */
  1324. #ifdef HARTMUT_0
  1325. while ((o = getopt_long(argc, argv, options, longopts, &longindex)) != -1) {
  1326. #else
  1327. while ((o = getopt(argc, argv, options)) != -1) {
  1328. #endif
  1329. /* Skip unknown arguments. */
  1330. if (o == '?') {
  1331. continue;
  1332. }
  1333. /* Prepare the option character and the argument string. */
  1334. if(o == 0) {
  1335. #ifdef HARTMUT_0
  1336. optname = (char *)longopts[longindex].name;
  1337. #else
  1338. /* o == 0 shall never happen so this only fixes a compiler warning */
  1339. optname = NULL;
  1340. #endif
  1341. } else {
  1342. if(o == 1) o = '-';
  1343. opt[0] = o;
  1344. optname = opt;
  1345. }
  1346. MAKE_STD_ZVAL(val);
  1347. if (optarg != NULL) {
  1348. ZVAL_STRING(val, optarg, 1);
  1349. } else {
  1350. ZVAL_FALSE(val);
  1351. }
  1352. /* Add this option / argument pair to the result hash. */
  1353. if(zend_hash_find(HASH_OF(return_value), optname, strlen(optname)+1, (void **)&args) != FAILURE) {
  1354. if(Z_TYPE_PP(args) != IS_ARRAY) {
  1355. convert_to_array_ex(args);
  1356. }
  1357. zend_hash_next_index_insert(HASH_OF(*args), (void *)&val, sizeof(zval *), NULL);
  1358. } else {
  1359. zend_hash_add(HASH_OF(return_value), optname, strlen(optname)+1, (void *)&val,
  1360. sizeof(zval *), NULL);
  1361. }
  1362. }
  1363. free_argv(argv, argc);
  1364. #ifdef HARTMUT_0
  1365. free_longopts(longopts);
  1366. #endif
  1367. }
  1368. /* }}} */
  1369. #endif
  1370. /* {{{ proto void flush(void)
  1371. Flush the output buffer */
  1372. PHP_FUNCTION(flush)
  1373. {
  1374. sapi_flush(TSRMLS_C);
  1375. }
  1376. /* }}} */
  1377. /* {{{ proto void sleep(int seconds)
  1378. Delay for a given number of seconds */
  1379. PHP_FUNCTION(sleep)
  1380. {
  1381. pval **num;
  1382. if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) {
  1383. WRONG_PARAM_COUNT;
  1384. }
  1385. convert_to_long_ex(num);
  1386. php_sleep(Z_LVAL_PP(num));
  1387. }
  1388. /* }}} */
  1389. /* {{{ proto void usleep(int micro_seconds)
  1390. Delay for a given number of micro seconds */
  1391. PHP_FUNCTION(usleep)
  1392. {
  1393. #if HAVE_USLEEP
  1394. pval **num;
  1395. if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) {
  1396. WRONG_PARAM_COUNT;
  1397. }
  1398. convert_to_long_ex(num);
  1399. usleep(Z_LVAL_PP(num));
  1400. #endif
  1401. }
  1402. /* }}} */
  1403. #if HAVE_NANOSLEEP
  1404. /* {{{ proto mixed time_nanosleep(long seconds, long nanoseconds)
  1405. Delay for a number of seconds and nano seconds */
  1406. PHP_FUNCTION(time_nanosleep)
  1407. {
  1408. long tv_sec, tv_nsec;
  1409. struct timespec php_req, php_rem;
  1410. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &tv_sec, &tv_nsec)) {
  1411. WRONG_PARAM_COUNT;
  1412. }
  1413. php_req.tv_sec = (time_t) tv_sec;
  1414. php_req.tv_nsec = tv_nsec;
  1415. if (!nanosleep(&php_req, &php_rem)) {
  1416. RETURN_TRUE;
  1417. } else if (errno == EINTR) {
  1418. array_init(return_value);
  1419. add_assoc_long_ex(return_value, "seconds", sizeof("seconds"), php_rem.tv_sec);
  1420. add_assoc_long_ex(return_value, "nanoseconds", sizeof("nanoseconds"), php_rem.tv_nsec);
  1421. return;
  1422. } else if (errno == EINVAL) {
  1423. php_error_docref(NULL TSRMLS_CC, E_WARNING, "nanoseconds was not in the range 0 to 999 999 999 or seconds was negative");
  1424. }
  1425. RETURN_FALSE;
  1426. }
  1427. /* }}} */
  1428. #endif
  1429. /* {{{ proto string get_current_user(void)
  1430. Get the name of the owner of the current PHP script */
  1431. PHP_FUNCTION(get_current_user)
  1432. {
  1433. if (ZEND_NUM_ARGS() != 0) {
  1434. WRONG_PARAM_COUNT;
  1435. }
  1436. RETURN_STRING(php_get_current_user(), 1);
  1437. }
  1438. /* }}} */
  1439. /* {{{ proto string get_cfg_var(string option_name)
  1440. Get the value of a PHP configuration option */
  1441. PHP_FUNCTION(get_cfg_var)
  1442. {
  1443. pval **varname;
  1444. char *value;
  1445. if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &varname) == FAILURE) {
  1446. WRONG_PARAM_COUNT;
  1447. }
  1448. convert_to_string_ex(varname);
  1449. if (cfg_get_string(Z_STRVAL_PP(varname), &value) == FAILURE) {
  1450. RETURN_FALSE;
  1451. }
  1452. RETURN_STRING(value, 1);
  1453. }
  1454. /* }}} */
  1455. /* {{{ proto bool set_magic_quotes_runtime(int new_setting)
  1456. Set the current active configuration setting of magic_quotes_runtime and return previous */
  1457. PHP_FUNCTION(set_magic_quotes_runtime)
  1458. {
  1459. pval **new_setting;
  1460. if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &new_setting) == FAILURE) {
  1461. RETURN_FALSE;
  1462. }
  1463. convert_to_boolean_ex(new_setting);
  1464. PG(magic_quotes_runtime) = (zend_bool) Z_LVAL_PP(new_setting);
  1465. RETURN_TRUE;
  1466. }
  1467. /* }}} */
  1468. /* {{{ proto int get_magic_quotes_runtime(void)
  1469. Get the current active configuration setting of magic_quotes_runtime */
  1470. PHP_FUNCTION(get_magic_quotes_runtime)
  1471. {
  1472. RETURN_LONG(PG(magic_quotes_runtime));
  1473. }
  1474. /* }}} */
  1475. /* {{{ proto int get_magic_quotes_gpc(void)
  1476. Get the current active configuration setting of magic_quotes_gpc */
  1477. PHP_FUNCTION(get_magic_quotes_gpc)
  1478. {
  1479. RETURN_LONG(PG(magic_quotes_gpc));
  1480. }
  1481. /* }}} */
  1482. /*
  1483. 1st arg = error message
  1484. 2nd arg = error option
  1485. 3rd arg = optional parameters (email address or tcp address)
  1486. 4th arg = used for additional headers if email
  1487. error options:
  1488. 0 = send to php_error_log (uses syslog or file depending on ini setting)
  1489. 1 = send via email to 3rd parameter 4th option = additional headers
  1490. 2 = send via tcp/ip to 3rd parameter (name or ip:port)
  1491. 3 = save to file in 3rd parameter
  1492. */
  1493. /* {{{ proto bool error_log(string message [, int message_type [, string destination [, string extra_headers]]])
  1494. Send an error message somewhere */
  1495. PHP_FUNCTION(error_log)
  1496. {
  1497. pval **string, **erropt = NULL, **option = NULL, **emailhead = NULL;
  1498. int opt_err = 0;
  1499. char *message, *opt = NULL, *headers = NULL;
  1500. switch (ZEND_NUM_ARGS()) {
  1501. case 1:
  1502. if (zend_get_parameters_ex(1, &string) == FAILURE) {
  1503. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument 1 invalid");
  1504. RETURN_FALSE;
  1505. }
  1506. break;
  1507. case 2:
  1508. if (zend_get_parameters_ex(2, &string, &erropt) == FAILURE) {
  1509. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid arguments");
  1510. RETURN_FALSE;
  1511. }
  1512. convert_to_long_ex(erropt);
  1513. opt_err = Z_LVAL_PP(erropt);
  1514. break;
  1515. case 3:
  1516. if (zend_get_parameters_ex(3, &string, &erropt, &option) == FAILURE) {
  1517. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid arguments");
  1518. RETURN_FALSE;
  1519. }
  1520. convert_to_long_ex(erropt);
  1521. opt_err = Z_LVAL_PP(erropt);
  1522. convert_to_string_ex(option);
  1523. opt = Z_STRVAL_PP(option);
  1524. break;
  1525. case 4:
  1526. if (zend_get_parameters_ex (4, &string, &erropt, &option, &emailhead) == FAILURE) {
  1527. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid arguments");
  1528. RETURN_FALSE;
  1529. }
  1530. break;
  1531. default:
  1532. WRONG_PARAM_COUNT;
  1533. }
  1534. convert_to_string_ex(string);
  1535. message = Z_STRVAL_PP(string);
  1536. if (erropt != NULL) {
  1537. convert_to_long_ex(erropt);
  1538. opt_err = Z_LVAL_PP(erropt);
  1539. }
  1540. if (option != NULL) {
  1541. convert_to_string_ex(option);
  1542. opt = Z_STRVAL_PP(option);
  1543. }
  1544. if (emailhead != NULL) {
  1545. convert_to_string_ex(emailhead);
  1546. headers = Z_STRVAL_PP(emailhead);
  1547. }
  1548. if (_php_error_log(opt_err, message, opt, headers TSRMLS_CC) == FAILURE) {
  1549. RETURN_FALSE;
  1550. }
  1551. RETURN_TRUE;
  1552. }
  1553. /* }}} */
  1554. PHPAPI int _php_error_log(int opt_err, char *message, char *opt, char *headers TSRMLS_DC)
  1555. {
  1556. php_stream *stream = NULL;
  1557. switch (opt_err) {
  1558. case 1: /*send an email */
  1559. {
  1560. #if HAVE_SENDMAIL
  1561. if (!php_mail(opt, "PHP error_log message", message, headers, NULL TSRMLS_CC)) {
  1562. return FAILURE;
  1563. }
  1564. #else
  1565. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Mail option not available!");
  1566. return FAILURE;
  1567. #endif
  1568. }
  1569. break;
  1570. case 2: /*send to an address */
  1571. php_error_docref(NULL TSRMLS_CC, E_WARNING, "TCP/IP option not available!");
  1572. return FAILURE;
  1573. break;
  1574. case 3: /*save to a file */
  1575. stream = php_stream_open_wrapper(opt, "a", IGNORE_URL | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL);
  1576. if (!stream)
  1577. return FAILURE;
  1578. php_stream_write(stream, message, strlen(message));
  1579. php_stream_close(stream);
  1580. break;
  1581. default:
  1582. php_log_err(message TSRMLS_CC);
  1583. break;
  1584. }
  1585. return SUCCESS;
  1586. }
  1587. /* {{{ proto mixed call_user_func(string function_name [, mixed parmeter] [, mixed ...])
  1588. Call a user function which is the first parameter */
  1589. PHP_FUNCTION(call_user_func)
  1590. {
  1591. zval ***params;
  1592. zval *retval_ptr;
  1593. char *name;
  1594. int argc = ZEND_NUM_ARGS();
  1595. if (argc < 1) {
  1596. WRONG_PARAM_COUNT;
  1597. }
  1598. params = safe_emalloc(sizeof(zval **), argc, 0);
  1599. if (zend_get_parameters_array_ex(argc, params) == FAILURE) {
  1600. efree(params);
  1601. RETURN_FALSE;
  1602. }
  1603. if (Z_TYPE_PP(params[0]) != IS_STRING && Z_TYPE_PP(params[0]) != IS_ARRAY) {
  1604. SEPARATE_ZVAL(params[0]);
  1605. convert_to_string_ex(params[0]);
  1606. }
  1607. if (!zend_is_callable(*params[0], 0, &name)) {
  1608. php_error_docref1(NULL TSRMLS_CC, name, E_WARNING, "First argument is expected to be a valid callback");
  1609. efree(name);
  1610. efree(params);
  1611. RETURN_NULL();
  1612. }
  1613. if (call_user_function_ex(EG(function_table), NULL, *params[0], &retval_ptr, argc-1, params+1, 0, NULL TSRMLS_CC) == SUCCESS) {
  1614. if (retval_ptr) {
  1615. COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr);
  1616. }
  1617. } else {
  1618. if (argc > 1) {
  1619. SEPARATE_ZVAL(params[1]);
  1620. convert_to_string_ex(params[1]);
  1621. if (argc > 2) {
  1622. SEPARATE_ZVAL(params[2]);
  1623. convert_to_string_ex(params[2]);
  1624. php_error_docref1(NULL TSRMLS_CC, name, E_WARNING, "Unable to call %s(%s,%s)", name, Z_STRVAL_PP(params[1]), Z_STRVAL_PP(params[2]));
  1625. } else {
  1626. php_error_docref1(NULL TSRMLS_CC, name, E_WARNING, "Unable to call %s(%s)", name, Z_STRVAL_PP(params[1]));
  1627. }
  1628. } else {
  1629. php_error_docref1(NULL TSRMLS_CC, name, E_WARNING, "Unable to call %s()", name);
  1630. }
  1631. }
  1632. efree(name);
  1633. efree(params);
  1634. }
  1635. /* }}} */
  1636. /* {{{ proto mixed call_user_func_array(string function_name, array parameters)
  1637. Call a user function which is the first parameter with the arguments contained in array */
  1638. PHP_FUNCTION(call_user_func_array)
  1639. {
  1640. zval ***func_params, **func, **params;
  1641. zval *retval_ptr;
  1642. HashTable *func_params_ht;
  1643. char *name;
  1644. int count;
  1645. int current = 0;
  1646. if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &func, &params) == FAILURE) {
  1647. WRONG_PARAM_COUNT;
  1648. }
  1649. SEPARATE_ZVAL(params);
  1650. convert_to_array_ex(params);
  1651. if (Z_TYPE_PP(func) != IS_STRING && Z_TYPE_PP(func) != IS_ARRAY) {
  1652. SEPARATE_ZVAL(func);
  1653. convert_to_string_ex(func);
  1654. }
  1655. if (!zend_is_callable(*func, 0, &name)) {
  1656. php_error_docref(NULL TSRMLS_CC, E_WARNING, "First argumented is expected to be a valid callback, '%s' was given", name);
  1657. efree(name);
  1658. RETURN_NULL();
  1659. }
  1660. func_params_ht = Z_ARRVAL_PP(params);
  1661. count = zend_hash_num_elements(func_params_ht);
  1662. func_params = safe_emalloc(sizeof(zval **), count, 0);
  1663. for (zend_hash_internal_pointer_reset(func_params_ht);
  1664. zend_hash_get_current_data(func_params_ht, (void **) &func_params[current]) == SUCCESS;
  1665. zend_hash_move_forward(func_params_ht)
  1666. ) {
  1667. current++;
  1668. }
  1669. if (call_user_function_ex(EG(function_table), NULL, *func, &retval_ptr, count, func_params, 0, NULL TSRMLS_CC) == SUCCESS && retval_ptr) {
  1670. COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr);
  1671. } else {
  1672. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call %s()", name);
  1673. }
  1674. efree(name);
  1675. efree(func_params);
  1676. }
  1677. /* }}} */
  1678. #define _CUM_DEPREC "This function is deprecated, use the call_user_func variety with the array(&$obj, \"method\") syntax instead"
  1679. /* {{{ proto mixed call_user_method(string method_name, mixed object [, mixed parameter] [, mixed ...])
  1680. Call a user method on a specific object or class */
  1681. PHP_FUNCTION(call_user_method)
  1682. {
  1683. zval ***params;
  1684. zval *retval_ptr;
  1685. int arg_count = ZEND_NUM_ARGS();
  1686. php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%s", _CUM_DEPREC);
  1687. if (arg_count < 2) {
  1688. WRONG_PARAM_COUNT;
  1689. }
  1690. params = (zval ***) safe_emalloc(sizeof(zval **), arg_count, 0);
  1691. if (zend_get_parameters_array_ex(arg_count, params) == FAILURE) {
  1692. efree(params);
  1693. RETURN_FALSE;
  1694. }
  1695. if (Z_TYPE_PP(params[1]) != IS_OBJECT && Z_TYPE_PP(params[1]) != IS_STRING) {
  1696. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Second argument is not an object or class name");
  1697. efree(params);
  1698. RETURN_FALSE;
  1699. }
  1700. SEPARATE_ZVAL(params[0]);
  1701. convert_to_string(*params[0]);
  1702. if (call_user_function_ex(EG(function_table), params[1], *params[0], &retval_ptr, arg_count-2, params+2, 0, NULL TSRMLS_CC) == SUCCESS && retval_ptr) {
  1703. COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr);
  1704. } else {
  1705. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call %s()", Z_STRVAL_PP(params[0]));
  1706. }
  1707. efree(params);
  1708. }
  1709. /* }}} */
  1710. /* {{{ proto mixed call_user_method_array(string method_name, mixed object, array params)
  1711. Call a user method on a specific object or class using a parameter array */
  1712. PHP_FUNCTION(call_user_method_array)
  1713. {
  1714. zval **method_name, **obj, **params, ***method_args = NULL, *retval_ptr;
  1715. HashTable *params_ar;
  1716. int num_elems, element = 0;
  1717. php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%s", _CUM_DEPREC);
  1718. if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &method_name, &obj, &params) == FAILURE) {
  1719. WRONG_PARAM_COUNT;
  1720. }
  1721. if (Z_TYPE_PP(obj) != IS_OBJECT && Z_TYPE_PP(obj) != IS_STRING) {
  1722. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Second argument is not an object or class name");
  1723. RETURN_FALSE;
  1724. }
  1725. SEPARATE_ZVAL(method_name);
  1726. SEPARATE_ZVAL(params);
  1727. convert_to_string_ex(method_name);
  1728. convert_to_array_ex(params);
  1729. params_ar = HASH_OF(*params);
  1730. num_elems = zend_hash_num_elements(params_ar);
  1731. method_args = (zval ***) safe_emalloc(sizeof(zval **), num_elems, 0);
  1732. for (zend_hash_internal_pointer_reset(params_ar);
  1733. zend_hash_get_current_data(params_ar, (void **) &(method_args[element])) == SUCCESS;
  1734. zend_hash_move_forward(params_ar)
  1735. ) {
  1736. element++;
  1737. }
  1738. if (call_user_function_ex(EG(function_table), obj, *method_name, &retval_ptr, num_elems, method_args, 0, NULL TSRMLS_CC) == SUCCESS && retval_ptr) {
  1739. COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr);
  1740. } else {
  1741. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call %s()", Z_STRVAL_PP(method_name));
  1742. }
  1743. efree(method_args);
  1744. }
  1745. /* }}} */
  1746. void user_shutdown_function_dtor(php_shutdown_function_entry *shutdown_function_entry)
  1747. {
  1748. int i;
  1749. for (i = 0; i < shutdown_function_entry->arg_count; i++) {
  1750. zval_ptr_dtor(&shutdown_function_entry->arguments[i]);
  1751. }
  1752. efree(shutdown_function_entry->arguments);
  1753. }
  1754. void user_tick_function_dtor(user_tick_function_entry *tick_function_entry)
  1755. {
  1756. int i;
  1757. for (i = 0; i < tick_function_entry->arg_count; i++) {
  1758. zval_ptr_dtor(&tick_function_entry->arguments[i]);
  1759. }
  1760. efree(tick_function_entry->arguments);
  1761. }
  1762. static int user_shutdown_function_call(php_shutdown_function_entry *shutdown_function_entry TSRMLS_DC)
  1763. {
  1764. zval retval;
  1765. if (call_user_function( EG(function_table), NULL,
  1766. shutdown_function_entry->arguments[0],
  1767. &retval,
  1768. shutdown_function_entry->arg_count - 1,
  1769. shutdown_function_entry->arguments + 1
  1770. TSRMLS_CC ) == SUCCESS ) {
  1771. zval_dtor(&retval);
  1772. } else {
  1773. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call %s() - function does not exist", Z_STRVAL_P(shutdown_function_entry->arguments[0]));
  1774. }
  1775. return 0;
  1776. }
  1777. static void user_tick_function_call(user_tick_function_entry *tick_fe TSRMLS_DC)
  1778. {
  1779. zval retval;
  1780. zval *function = tick_fe->arguments[0];
  1781. /* Prevent reentrant calls to the same user ticks function */
  1782. if (! tick_fe->calling) {
  1783. tick_fe->calling = 1;
  1784. if (call_user_function( EG(function_table), NULL,
  1785. function,
  1786. &retval,
  1787. tick_fe->arg_count - 1,
  1788. tick_fe->arguments+1
  1789. TSRMLS_CC) == SUCCESS) {
  1790. zval_dtor(&retval);
  1791. } else {
  1792. zval **obj, **method;
  1793. if (Z_TYPE_P(function) == IS_STRING) {
  1794. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call %s() - function does not exist", Z_STRVAL_P(function));
  1795. } else if ( Z_TYPE_P(function) == IS_ARRAY
  1796. && zend_hash_index_find(Z_ARRVAL_P(function), 0, (void **) &obj) == SUCCESS
  1797. && zend_hash_index_find(Z_ARRVAL_P(function), 1, (void **) &method) == SUCCESS
  1798. && Z_TYPE_PP(obj) == IS_OBJECT
  1799. && Z_TYPE_PP(method) == IS_STRING ) {
  1800. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call %s::%s() - function does not exist", Z_OBJCE_PP(obj)->name, Z_STRVAL_PP(method));
  1801. } else {
  1802. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call tick function");
  1803. }
  1804. }
  1805. tick_fe->calling = 0;
  1806. }
  1807. }
  1808. static void run_user_tick_functions(int tick_count)
  1809. {
  1810. TSRMLS_FETCH();
  1811. zend_llist_apply(BG(user_tick_functions), (llist_apply_func_t) user_tick_function_call TSRMLS_CC);
  1812. }
  1813. static int user_tick_function_compare(user_tick_function_entry * tick_fe1, user_tick_function_entry * tick_fe2)
  1814. {
  1815. zval *func1 = tick_fe1->arguments[0];
  1816. zval *func2 = tick_fe2->arguments[0];
  1817. TSRMLS_FETCH();
  1818. if (Z_TYPE_P(func1) == IS_STRING && Z_TYPE_P(func2) == IS_STRING) {
  1819. return (zend_binary_zval_strcmp(func1, func2) == 0);
  1820. } else if (Z_TYPE_P(func1) == IS_ARRAY && Z_TYPE_P(func2) == IS_ARRAY) {
  1821. zval result;
  1822. zend_compare_arrays(&result, func1, func2 TSRMLS_CC);
  1823. return (Z_LVAL(result) == 0);
  1824. } else {
  1825. return 0;
  1826. }
  1827. }
  1828. void php_call_shutdown_functions(void)
  1829. {
  1830. TSRMLS_FETCH();
  1831. if (BG(user_shutdown_function_names))
  1832. zend_try {
  1833. zend_hash_apply(BG(user_shutdown_function_names), (apply_func_t) user_shutdown_function_call TSRMLS_CC);
  1834. memcpy(&EG(bailout), &orig_bailout, sizeof(jmp_buf));
  1835. zend_hash_destroy(BG(user_shutdown_function_names));
  1836. efree(BG(user_shutdown_function_names));
  1837. }
  1838. zend_end_try();
  1839. }
  1840. /* {{{ proto void register_shutdown_function(string function_name)
  1841. Register a user-level function to be called on request termination */
  1842. PHP_FUNCTION(register_shutdown_function)
  1843. {
  1844. php_shutdown_function_entry shutdown_function_entry;
  1845. int i;
  1846. shutdown_function_entry.arg_count = ZEND_NUM_ARGS();
  1847. if (shutdown_function_entry.arg_count < 1) {
  1848. WRONG_PARAM_COUNT;
  1849. }
  1850. shutdown_function_entry.arguments = (pval **) safe_emalloc(sizeof(pval *), shutdown_function_entry.arg_count, 0);
  1851. if (zend_get_parameters_array(ht, shutdown_function_entry.arg_count, shutdown_function_entry.arguments) == FAILURE) {
  1852. RETURN_FALSE;
  1853. }
  1854. /* Prevent entering of anything but arrays/strings */
  1855. if (Z_TYPE_P(shutdown_function_entry.arguments[0]) != IS_ARRAY) {
  1856. convert_to_string(shutdown_function_entry.arguments[0]);
  1857. }
  1858. if (!BG(user_shutdown_function_names)) {
  1859. ALLOC_HASHTABLE(BG(user_shutdown_function_names));
  1860. zend_hash_init(BG(user_shutdown_function_names), 0, NULL, (void (*)(void *)) user_shutdown_function_dtor, 0);
  1861. }
  1862. for (i = 0; i < shutdown_function_entry.arg_count; i++) {
  1863. shutdown_function_entry.arguments[i]->refcount++;
  1864. }
  1865. zend_hash_next_index_insert(BG(user_shutdown_function_names), &shutdown_function_entry, sizeof(php_shutdown_function_entry), NULL);
  1866. }
  1867. /* }}} */
  1868. ZEND_API void php_get_highlight_struct(zend_syntax_highlighter_ini *syntax_highlighter_ini)
  1869. {
  1870. syntax_highlighter_ini->highlight_comment = INI_STR("highlight.comment");
  1871. syntax_highlighter_ini->highlight_default = INI_STR("highlight.default");
  1872. syntax_highlighter_ini->highlight_html = INI_STR("highlight.html");
  1873. syntax_highlighter_ini->highlight_keyword = INI_STR("highlight.keyword");
  1874. syntax_highlighter_ini->highlight_string = INI_STR("highlight.string");
  1875. }
  1876. /* {{{ proto bool highlight_file(string file_name [, bool return] )
  1877. Syntax highlight a source file */
  1878. PHP_FUNCTION(highlight_file)
  1879. {
  1880. zval *filename;
  1881. zend_syntax_highlighter_ini syntax_highlighter_ini;
  1882. zend_bool i = 0;
  1883. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &filename, &i) == FAILURE) {
  1884. RETURN_FALSE;
  1885. }
  1886. convert_to_string(filename);
  1887. if (PG(safe_mode) && (!php_checkuid(Z_STRVAL_P(filename), NULL, CHECKUID_ALLOW_ONLY_FILE))) {
  1888. RETURN_FALSE;
  1889. }
  1890. if (php_check_open_basedir(Z_STRVAL_P(filename) TSRMLS_CC)) {
  1891. RETURN_FALSE;
  1892. }
  1893. if (i) {
  1894. php_start_ob_buffer (NULL, 0, 1 TSRMLS_CC);
  1895. }
  1896. php_get_highlight_struct(&syntax_highlighter_ini);
  1897. if (highlight_file(Z_STRVAL_P(filename), &syntax_highlighter_ini TSRMLS_CC) == FAILURE) {
  1898. RETURN_FALSE;
  1899. }
  1900. if (i) {
  1901. php_ob_get_buffer (return_value TSRMLS_CC);
  1902. php_end_ob_buffer (0, 0 TSRMLS_CC);
  1903. } else {
  1904. RETURN_TRUE;
  1905. }
  1906. }
  1907. /* }}} */
  1908. /* {{{ proto string php_strip_whitespace(string file_name)
  1909. Return source with stripped comments and whitespace */
  1910. PHP_FUNCTION(php_strip_whitespace)
  1911. {
  1912. char *filename;
  1913. int filename_len;
  1914. zend_lex_state original_lex_state;
  1915. zend_file_handle file_handle = {0};
  1916. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
  1917. RETURN_FALSE;
  1918. }
  1919. php_start_ob_buffer(NULL, 0, 1 TSRMLS_CC);
  1920. file_handle.type = ZEND_HANDLE_FILENAME;
  1921. file_handle.filename = filename;
  1922. file_handle.free_filename = 0;
  1923. file_handle.opened_path = NULL;
  1924. zend_save_lexical_state(&original_lex_state TSRMLS_CC);
  1925. if (open_file_for_scanning(&file_handle TSRMLS_CC)==FAILURE) {
  1926. RETURN_EMPTY_STRING();
  1927. }
  1928. zend_strip(TSRMLS_C);
  1929. zend_destroy_file_handle(&file_handle TSRMLS_CC);
  1930. zend_restore_lexical_state(&original_lex_state TSRMLS_CC);
  1931. php_ob_get_buffer(return_value TSRMLS_CC);
  1932. php_end_ob_buffer(0, 0 TSRMLS_CC);
  1933. return;
  1934. }
  1935. /* }}} */
  1936. /* {{{ proto bool php_check_syntax(string file_name [, &$error_message])
  1937. Check the syntax of the specified file. */
  1938. PHP_FUNCTION(php_check_syntax)
  1939. {
  1940. char *filename;
  1941. int filename_len;
  1942. zval *errm=NULL;
  1943. zend_file_handle file_handle = {0};
  1944. int old_errors = PG(display_errors);
  1945. int log_errors = PG(log_errors);
  1946. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z", &filename, &filename_len, &errm) == FAILURE) {
  1947. RETURN_FALSE;
  1948. }
  1949. file_handle.type = ZEND_HANDLE_FILENAME;
  1950. file_handle.filename = filename;
  1951. file_handle.free_filename = 0;
  1952. file_handle.opened_path = NULL;
  1953. PG(log_errors) = PG(display_errors) = 0;
  1954. if (php_lint_script(&file_handle TSRMLS_CC) != SUCCESS) {
  1955. if (errm && PZVAL_IS_REF(errm)) {
  1956. char *error_str;
  1957. convert_to_string_ex(&errm);
  1958. spprintf(&error_str, 0, "%s in %s on line %d", PG(last_error_message), PG(last_error_file), PG(last_error_lineno));
  1959. ZVAL_STRING(errm, error_str, 0);
  1960. }
  1961. RETVAL_FALSE;
  1962. } else {
  1963. RETVAL_TRUE;
  1964. }
  1965. PG(display_errors) = old_errors;
  1966. PG(log_errors) = log_errors;
  1967. return;
  1968. }
  1969. /* }}} */
  1970. /* {{{ proto bool highlight_string(string string [, bool return] )
  1971. Syntax highlight a string or optionally return it */
  1972. PHP_FUNCTION(highlight_string)
  1973. {
  1974. zval *expr;
  1975. zend_syntax_highlighter_ini syntax_highlighter_ini;
  1976. char *hicompiled_string_description;
  1977. zend_bool i = 0;
  1978. int old_error_reporting = EG(error_reporting);
  1979. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &expr, &i) == FAILURE) {
  1980. RETURN_FALSE;
  1981. }
  1982. convert_to_string(expr);
  1983. if (i) {
  1984. php_start_ob_buffer (NULL, 0, 1 TSRMLS_CC);
  1985. }
  1986. EG(error_reporting) = E_ERROR;
  1987. php_get_highlight_struct(&syntax_highlighter_ini);
  1988. hicompiled_string_description = zend_make_compiled_string_description("highlighted code" TSRMLS_CC);
  1989. if (highlight_string(expr, &syntax_highlighter_ini, hicompiled_string_description TSRMLS_CC) == FAILURE) {
  1990. efree(hicompiled_string_description);
  1991. RETURN_FALSE;
  1992. }
  1993. efree(hicompiled_string_description);
  1994. EG(error_reporting) = old_error_reporting;
  1995. if (i) {
  1996. php_ob_get_buffer (return_value TSRMLS_CC);
  1997. php_end_ob_buffer (0, 0 TSRMLS_CC);
  1998. } else {
  1999. RETURN_TRUE;
  2000. }
  2001. }
  2002. /* }}} */
  2003. /* {{{ proto string ini_get(string varname)
  2004. Get a configuration option */
  2005. PHP_FUNCTION(ini_get)
  2006. {
  2007. pval **varname;
  2008. char *str;
  2009. if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &varname) == FAILURE) {
  2010. WRONG_PARAM_COUNT;
  2011. }
  2012. convert_to_string_ex(varname);
  2013. str = zend_ini_string(Z_STRVAL_PP(varname), Z_STRLEN_PP(varname)+1, 0);
  2014. if (!str) {
  2015. RETURN_FALSE;
  2016. }
  2017. RETURN_STRING(str, 1);
  2018. }
  2019. /* }}} */
  2020. static int php_ini_get_option(zend_ini_entry *ini_entry, int num_args, va_list args, zend_hash_key *hash_key)
  2021. {
  2022. zval *ini_array = va_arg(args, zval *);
  2023. int module_number = va_arg(args, int);
  2024. zval *option;
  2025. if (module_number != 0 && ini_entry->module_number != module_number) {
  2026. return 0;
  2027. }
  2028. if (hash_key->nKeyLength == 0 || hash_key->arKey[0] != 0) {
  2029. MAKE_STD_ZVAL(option);
  2030. array_init(option);
  2031. if (ini_entry->orig_value) {
  2032. add_assoc_stringl(option, "global_value", ini_entry->orig_value, ini_entry->orig_value_length, 1);
  2033. } else if (ini_entry->value) {
  2034. add_assoc_stringl(option, "global_value", ini_entry->value, ini_entry->value_length, 1);
  2035. } else {
  2036. add_assoc_null(option, "global_value");
  2037. }
  2038. if (ini_entry->value) {
  2039. add_assoc_stringl(option, "local_value", ini_entry->value, ini_entry->value_length, 1);
  2040. } else {
  2041. add_assoc_null(option, "local_value");
  2042. }
  2043. add_assoc_long(option, "access", ini_entry->modifiable);
  2044. add_assoc_zval_ex(ini_array, ini_entry->name, ini_entry->name_length, option);
  2045. }
  2046. return 0;
  2047. }
  2048. /* {{{ proto array ini_get_all([string extension])
  2049. Get all configuration options */
  2050. PHP_FUNCTION(ini_get_all)
  2051. {
  2052. char *extname = NULL;
  2053. int extname_len = 0, extnumber = 0;
  2054. zend_module_entry *module;
  2055. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &extname, &extname_len) == FAILURE) {
  2056. RETURN_FALSE;
  2057. }
  2058. zend_ini_sort_entries(TSRMLS_C);
  2059. if (extname) {
  2060. if (zend_hash_find(&module_registry, extname, extname_len+1, (void **) &module) == FAILURE) {
  2061. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find extension '%s'", extname);
  2062. RETURN_FALSE;
  2063. }
  2064. extnumber = module->module_number;
  2065. }
  2066. array_init(return_value);
  2067. zend_hash_apply_with_arguments(EG(ini_directives), (apply_func_args_t) php_ini_get_option, 2, return_value, extnumber TSRMLS_CC);
  2068. }
  2069. /* }}} */
  2070. static int php_ini_check_path(char *option_name, int option_len, char *new_option_name, int new_option_len)
  2071. {
  2072. if ( option_len != (new_option_len-1) ) {
  2073. return 0;
  2074. }
  2075. return !strncmp(option_name, new_option_name, option_len);
  2076. }
  2077. /* {{{ proto string ini_set(string varname, string newvalue)
  2078. Set a configuration option, returns false on error and the old value of the configuration option on success */
  2079. PHP_FUNCTION(ini_set)
  2080. {
  2081. pval **varname, **new_value;
  2082. char *old_value;
  2083. if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &varname, &new_value) == FAILURE) {
  2084. WRONG_PARAM_COUNT;
  2085. }
  2086. convert_to_string_ex(varname);
  2087. convert_to_string_ex(new_value);
  2088. old_value = zend_ini_string(Z_STRVAL_PP(varname), Z_STRLEN_PP(varname)+1, 0);
  2089. /* copy to return here, because alter might free it! */
  2090. if (old_value) {
  2091. RETVAL_STRING(old_value, 1);
  2092. } else {
  2093. RETVAL_FALSE;
  2094. }
  2095. #define _CHECK_PATH(var, ini) php_ini_check_path(Z_STRVAL_PP(var), Z_STRLEN_PP(var), ini, sizeof(ini))
  2096. /* safe_mode & basedir check */
  2097. if (PG(safe_mode) || PG(open_basedir)) {
  2098. if (_CHECK_PATH(varname, "error_log") ||
  2099. _CHECK_PATH(varname, "java.class.path") ||
  2100. _CHECK_PATH(varname, "java.home") ||
  2101. _CHECK_PATH(varname, "java.library.path") ||
  2102. _CHECK_PATH(varname, "session.save_path") ||
  2103. _CHECK_PATH(varname, "vpopmail.directory")) {
  2104. if (PG(safe_mode) &&(!php_checkuid(Z_STRVAL_PP(new_value), NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
  2105. zval_dtor(return_value);
  2106. RETURN_FALSE;
  2107. }
  2108. if (php_check_open_basedir(Z_STRVAL_PP(new_value) TSRMLS_CC)) {
  2109. zval_dtor(return_value);
  2110. RETURN_FALSE;
  2111. }
  2112. }
  2113. }
  2114. /* checks that ensure the user does not overwrite certain ini settings when safe_mode is enabled */
  2115. if (PG(safe_mode)) {
  2116. if (!strncmp("max_execution_time", Z_STRVAL_PP(varname), sizeof("max_execution_time")) ||
  2117. !strncmp("memory_limit", Z_STRVAL_PP(varname), sizeof("memory_limit")) ||
  2118. !strncmp("child_terminate", Z_STRVAL_PP(varname), sizeof("child_terminate"))) {
  2119. zval_dtor(return_value);
  2120. RETURN_FALSE;
  2121. }
  2122. }
  2123. if (zend_alter_ini_entry(Z_STRVAL_PP(varname), Z_STRLEN_PP(varname)+1, Z_STRVAL_PP(new_value), Z_STRLEN_PP(new_value),
  2124. PHP_INI_USER, PHP_INI_STAGE_RUNTIME) == FAILURE) {
  2125. zval_dtor(return_value);
  2126. RETURN_FALSE;
  2127. }
  2128. }
  2129. /* }}} */
  2130. /* {{{ proto void ini_restore(string varname)
  2131. Restore the value of a configuration option specified by varname */
  2132. PHP_FUNCTION(ini_restore)
  2133. {
  2134. pval **varname;
  2135. if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &varname) == FAILURE) {
  2136. WRONG_PARAM_COUNT;
  2137. }
  2138. convert_to_string_ex(varname);
  2139. zend_restore_ini_entry(Z_STRVAL_PP(varname), Z_STRLEN_PP(varname)+1, PHP_INI_STAGE_RUNTIME);
  2140. }
  2141. /* }}} */
  2142. /* {{{ proto string set_include_path(string varname, string newvalue)
  2143. Sets the include_path configuration option */
  2144. PHP_FUNCTION(set_include_path)
  2145. {
  2146. pval **new_value;
  2147. char *old_value;
  2148. if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &new_value) == FAILURE) {
  2149. WRONG_PARAM_COUNT;
  2150. }
  2151. convert_to_string_ex(new_value);
  2152. old_value = zend_ini_string("include_path", sizeof("include_path"), 0);
  2153. /* copy to return here, because alter might free it! */
  2154. if (old_value) {
  2155. RETVAL_STRING(old_value, 1);
  2156. } else {
  2157. RETVAL_FALSE;
  2158. }
  2159. if (zend_alter_ini_entry("include_path", sizeof("include_path"),
  2160. Z_STRVAL_PP(new_value), Z_STRLEN_PP(new_value),
  2161. PHP_INI_USER, PHP_INI_STAGE_RUNTIME) == FAILURE) {
  2162. zval_dtor(return_value);
  2163. RETURN_FALSE;
  2164. }
  2165. }
  2166. /* }}} */
  2167. /* {{{ proto string get_include_path()
  2168. Get the current include_path configuration option */
  2169. PHP_FUNCTION(get_include_path)
  2170. {
  2171. char *str;
  2172. if (ZEND_NUM_ARGS() != 0) {
  2173. WRONG_PARAM_COUNT;
  2174. }
  2175. str = zend_ini_string("include_path", sizeof("include_path"), 0);
  2176. if (str == NULL) {
  2177. RETURN_FALSE;
  2178. }
  2179. RETURN_STRING(str, 1);
  2180. }
  2181. /* }}} */
  2182. /* {{{ proto void restore_include_path()
  2183. Restore the value of the include_path configuration option */
  2184. PHP_FUNCTION(restore_include_path)
  2185. {
  2186. if (ZEND_NUM_ARGS() != 0) {
  2187. WRONG_PARAM_COUNT;
  2188. }
  2189. zend_restore_ini_entry("include_path", sizeof("include_path"),
  2190. PHP_INI_STAGE_RUNTIME);
  2191. }
  2192. /* }}} */
  2193. /* {{{ proto mixed print_r(mixed var [, bool return])
  2194. Prints out or returns information about the specified variable */
  2195. PHP_FUNCTION(print_r)
  2196. {
  2197. zval *var;
  2198. zend_bool i = 0;
  2199. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &var, &i) == FAILURE) {
  2200. RETURN_FALSE;
  2201. }
  2202. if (i) {
  2203. php_start_ob_buffer (NULL, 0, 1 TSRMLS_CC);
  2204. }
  2205. zend_print_zval_r(var, 0 TSRMLS_CC);
  2206. if (i) {
  2207. php_ob_get_buffer (return_value TSRMLS_CC);
  2208. php_end_ob_buffer (0, 0 TSRMLS_CC);
  2209. } else {
  2210. RETURN_TRUE;
  2211. }
  2212. }
  2213. /* }}} */
  2214. /* This should go back to PHP */
  2215. /* {{{ proto int connection_aborted(void)
  2216. Returns true if client disconnected */
  2217. PHP_FUNCTION(connection_aborted)
  2218. {
  2219. RETURN_LONG(PG(connection_status) & PHP_CONNECTION_ABORTED);
  2220. }
  2221. /* }}} */
  2222. /* {{{ proto int connection_status(void)
  2223. Returns the connection status bitfield */
  2224. PHP_FUNCTION(connection_status)
  2225. {
  2226. RETURN_LONG(PG(connection_status));
  2227. }
  2228. /* }}} */
  2229. /* {{{ proto int ignore_user_abort(bool value)
  2230. Set whether we want to ignore a user abort event or not */
  2231. PHP_FUNCTION(ignore_user_abort)
  2232. {
  2233. pval **arg;
  2234. int old_setting;
  2235. old_setting = PG(ignore_user_abort);
  2236. switch (ZEND_NUM_ARGS()) {
  2237. case 0:
  2238. break;
  2239. case 1:
  2240. if (zend_get_parameters_ex(1, &arg) == FAILURE) {
  2241. RETURN_FALSE;
  2242. }
  2243. convert_to_string_ex(arg);
  2244. zend_alter_ini_entry("ignore_user_abort", sizeof("ignore_user_abort"), Z_STRVAL_PP(arg), Z_STRLEN_PP(arg), PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
  2245. break;
  2246. default:
  2247. WRONG_PARAM_COUNT;
  2248. break;
  2249. }
  2250. RETURN_LONG(old_setting);
  2251. }
  2252. /* }}} */
  2253. #if HAVE_GETSERVBYNAME
  2254. /* {{{ proto int getservbyname(string service, string protocol)
  2255. Returns port associated with service. Protocol must be "tcp" or "udp" */
  2256. PHP_FUNCTION(getservbyname)
  2257. {
  2258. pval **name, **proto;
  2259. struct servent *serv;
  2260. if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &name, &proto) == FAILURE) {
  2261. WRONG_PARAM_COUNT;
  2262. }
  2263. convert_to_string_ex(name);
  2264. convert_to_string_ex(proto);
  2265. serv = getservbyname(Z_STRVAL_PP(name), Z_STRVAL_PP(proto));
  2266. if (serv == NULL) {
  2267. RETURN_FALSE;
  2268. }
  2269. RETURN_LONG(ntohs(serv->s_port));
  2270. }
  2271. /* }}} */
  2272. #endif
  2273. #if HAVE_GETSERVBYPORT
  2274. /* {{{ proto string getservbyport(int port, string protocol)
  2275. Returns service name associated with port. Protocol must be "tcp" or "udp" */
  2276. PHP_FUNCTION(getservbyport)
  2277. {
  2278. pval **port, **proto;
  2279. struct servent *serv;
  2280. if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &port, &proto) == FAILURE) {
  2281. WRONG_PARAM_COUNT;
  2282. }
  2283. convert_to_long_ex(port);
  2284. convert_to_string_ex(proto);
  2285. serv = getservbyport(htons((unsigned short) Z_LVAL_PP(port)), Z_STRVAL_PP(proto));
  2286. if (serv == NULL) {
  2287. RETURN_FALSE;
  2288. }
  2289. RETURN_STRING(serv->s_name, 1);
  2290. }
  2291. /* }}} */
  2292. #endif
  2293. #if HAVE_GETPROTOBYNAME
  2294. /* {{{ proto int getprotobyname(string name)
  2295. Returns protocol number associated with name as per /etc/protocols */
  2296. PHP_FUNCTION(getprotobyname)
  2297. {
  2298. pval **name;
  2299. struct protoent *ent;
  2300. if (ZEND_NUM_ARGS() != 1
  2301. || zend_get_parameters_ex(1, &name) == FAILURE) {
  2302. WRONG_PARAM_COUNT;
  2303. }
  2304. convert_to_string_ex(name);
  2305. ent = getprotobyname(Z_STRVAL_PP(name));
  2306. if (ent == NULL) {
  2307. Z_LVAL_P(return_value) = -1;
  2308. Z_TYPE_P(return_value) = IS_LONG;
  2309. RETURN_FALSE;
  2310. }
  2311. RETURN_LONG(ent->p_proto);
  2312. }
  2313. /* }}} */
  2314. #endif
  2315. #if HAVE_GETPROTOBYNUMBER
  2316. /* {{{ proto string getprotobynumber(int proto)
  2317. Returns protocol name associated with protocol number proto */
  2318. PHP_FUNCTION(getprotobynumber)
  2319. {
  2320. pval **proto;
  2321. struct protoent *ent;
  2322. if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &proto) == FAILURE) {
  2323. WRONG_PARAM_COUNT;
  2324. }
  2325. convert_to_long_ex(proto);
  2326. ent = getprotobynumber(Z_LVAL_PP(proto));
  2327. if (ent == NULL) {
  2328. RETURN_FALSE;
  2329. }
  2330. RETURN_STRING(ent->p_name, 1);
  2331. }
  2332. /* }}} */
  2333. #endif
  2334. /* {{{ proto bool register_tick_function(string function_name [, mixed arg [, mixed ... ]])
  2335. Registers a tick callback function */
  2336. PHP_FUNCTION(register_tick_function)
  2337. {
  2338. user_tick_function_entry tick_fe;
  2339. int i;
  2340. tick_fe.calling = 0;
  2341. tick_fe.arg_count = ZEND_NUM_ARGS();
  2342. if (tick_fe.arg_count < 1) {
  2343. WRONG_PARAM_COUNT;
  2344. }
  2345. tick_fe.arguments = (zval **) safe_emalloc(sizeof(zval *), tick_fe.arg_count, 0);
  2346. if (zend_get_parameters_array(ht, tick_fe.arg_count, tick_fe.arguments) == FAILURE) {
  2347. RETURN_FALSE;
  2348. }
  2349. if (Z_TYPE_P(tick_fe.arguments[0]) != IS_ARRAY)
  2350. convert_to_string_ex(&tick_fe.arguments[0]);
  2351. if (!BG(user_tick_functions)) {
  2352. BG(user_tick_functions) = (zend_llist *) emalloc(sizeof(zend_llist));
  2353. zend_llist_init(BG(user_tick_functions),
  2354. sizeof(user_tick_function_entry),
  2355. (llist_dtor_func_t) user_tick_function_dtor, 0);
  2356. php_add_tick_function(run_user_tick_functions);
  2357. }
  2358. for (i = 0; i < tick_fe.arg_count; i++) {
  2359. tick_fe.arguments[i]->refcount++;
  2360. }
  2361. zend_llist_add_element(BG(user_tick_functions), &tick_fe);
  2362. RETURN_TRUE;
  2363. }
  2364. /* }}} */
  2365. /* {{{ proto void unregister_tick_function(string function_name)
  2366. Unregisters a tick callback function */
  2367. PHP_FUNCTION(unregister_tick_function)
  2368. {
  2369. zval **function;
  2370. user_tick_function_entry tick_fe;
  2371. if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &function)) {
  2372. WRONG_PARAM_COUNT;
  2373. }
  2374. if (!BG(user_tick_functions)) {
  2375. return;
  2376. }
  2377. if (Z_TYPE_PP(function) != IS_ARRAY) {
  2378. convert_to_string_ex(function);
  2379. }
  2380. tick_fe.arguments = (zval **) emalloc(sizeof(zval *));
  2381. tick_fe.arguments[0] = *function;
  2382. tick_fe.arg_count = 1;
  2383. zend_llist_del_element(BG(user_tick_functions), &tick_fe, (int (*)(void *, void *)) user_tick_function_compare);
  2384. efree(tick_fe.arguments);
  2385. }
  2386. /* }}} */
  2387. /* {{{ proto bool is_uploaded_file(string path)
  2388. Check if file was created by rfc1867 upload */
  2389. PHP_FUNCTION(is_uploaded_file)
  2390. {
  2391. zval **path;
  2392. if (!SG(rfc1867_uploaded_files)) {
  2393. RETURN_FALSE;
  2394. }
  2395. if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &path) != SUCCESS) {
  2396. ZEND_WRONG_PARAM_COUNT();
  2397. }
  2398. convert_to_string_ex(path);
  2399. if (zend_hash_exists(SG(rfc1867_uploaded_files), Z_STRVAL_PP(path), Z_STRLEN_PP(path)+1)) {
  2400. RETURN_TRUE;
  2401. } else {
  2402. RETURN_FALSE;
  2403. }
  2404. }
  2405. /* }}} */
  2406. /* {{{ proto bool move_uploaded_file(string path, string new_path)
  2407. Move a file if and only if it was created by an upload */
  2408. PHP_FUNCTION(move_uploaded_file)
  2409. {
  2410. zval **path, **new_path;
  2411. zend_bool successful = 0;
  2412. if (!SG(rfc1867_uploaded_files)) {
  2413. RETURN_FALSE;
  2414. }
  2415. if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &path, &new_path) != SUCCESS) {
  2416. ZEND_WRONG_PARAM_COUNT();
  2417. }
  2418. convert_to_string_ex(path);
  2419. convert_to_string_ex(new_path);
  2420. if (!zend_hash_exists(SG(rfc1867_uploaded_files), Z_STRVAL_PP(path), Z_STRLEN_PP(path)+1)) {
  2421. RETURN_FALSE;
  2422. }
  2423. if (PG(safe_mode) && (!php_checkuid(Z_STRVAL_PP(new_path), NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
  2424. RETURN_FALSE;
  2425. }
  2426. if (php_check_open_basedir(Z_STRVAL_PP(new_path) TSRMLS_CC)) {
  2427. RETURN_FALSE;
  2428. }
  2429. VCWD_UNLINK(Z_STRVAL_PP(new_path));
  2430. if (rename(Z_STRVAL_PP(path), Z_STRVAL_PP(new_path)) == 0) {
  2431. successful = 1;
  2432. } else
  2433. if (php_copy_file(Z_STRVAL_PP(path), Z_STRVAL_PP(new_path) TSRMLS_CC) == SUCCESS) {
  2434. VCWD_UNLINK(Z_STRVAL_PP(path));
  2435. successful = 1;
  2436. }
  2437. if (successful) {
  2438. zend_hash_del(SG(rfc1867_uploaded_files), Z_STRVAL_PP(path), Z_STRLEN_PP(path)+1);
  2439. } else {
  2440. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to move '%s' to '%s'", Z_STRVAL_PP(path), Z_STRVAL_PP(new_path));
  2441. }
  2442. RETURN_BOOL(successful);
  2443. }
  2444. /* }}} */
  2445. static void php_simple_ini_parser_cb(zval *arg1, zval *arg2, int callback_type, zval *arr)
  2446. {
  2447. zval *element;
  2448. switch (callback_type) {
  2449. case ZEND_INI_PARSER_ENTRY:
  2450. if (!arg2) {
  2451. /* bare string - nothing to do */
  2452. break;
  2453. }
  2454. ALLOC_ZVAL(element);
  2455. *element = *arg2;
  2456. zval_copy_ctor(element);
  2457. INIT_PZVAL(element);
  2458. if (is_numeric_string(Z_STRVAL_P(arg1), Z_STRLEN_P(arg1), NULL, NULL, 0) != IS_LONG) {
  2459. zend_hash_update(Z_ARRVAL_P(arr), Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, &element, sizeof(zval *), NULL);
  2460. } else {
  2461. ulong key = (ulong) zend_atoi(Z_STRVAL_P(arg1), Z_STRLEN_P(arg1));
  2462. zend_hash_index_update(Z_ARRVAL_P(arr), key, &element, sizeof(zval *), NULL);
  2463. }
  2464. break;
  2465. case ZEND_INI_PARSER_POP_ENTRY:
  2466. {
  2467. zval *hash, **find_hash;
  2468. if (!arg2) {
  2469. /* bare string - nothing to do */
  2470. break;
  2471. }
  2472. if (is_numeric_string(Z_STRVAL_P(arg1), Z_STRLEN_P(arg1), NULL, NULL, 0) != IS_LONG) {
  2473. if (zend_hash_find(Z_ARRVAL_P(arr), Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, (void **) &find_hash) == FAILURE) {
  2474. ALLOC_ZVAL(hash);
  2475. INIT_PZVAL(hash);
  2476. array_init(hash);
  2477. zend_hash_update(Z_ARRVAL_P(arr), Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, &hash, sizeof(zval *), NULL);
  2478. } else {
  2479. hash = *find_hash;
  2480. }
  2481. } else {
  2482. ulong key = (ulong) zend_atoi(Z_STRVAL_P(arg1), Z_STRLEN_P(arg1));
  2483. if (zend_hash_index_find(Z_ARRVAL_P(arr), key, (void **) &find_hash) == FAILURE) {
  2484. ALLOC_ZVAL(hash);
  2485. INIT_PZVAL(hash);
  2486. array_init(hash);
  2487. zend_hash_index_update(Z_ARRVAL_P(arr), key, &hash, sizeof(zval *), NULL);
  2488. } else {
  2489. hash = *find_hash;
  2490. }
  2491. }
  2492. ALLOC_ZVAL(element);
  2493. *element = *arg2;
  2494. zval_copy_ctor(element);
  2495. INIT_PZVAL(element);
  2496. add_next_index_zval(hash, element);
  2497. }
  2498. break;
  2499. case ZEND_INI_PARSER_SECTION:
  2500. break;
  2501. }
  2502. }
  2503. static void php_ini_parser_cb_with_sections(zval *arg1, zval *arg2, int callback_type, zval *arr)
  2504. {
  2505. TSRMLS_FETCH();
  2506. if (callback_type == ZEND_INI_PARSER_SECTION) {
  2507. MAKE_STD_ZVAL(BG(active_ini_file_section));
  2508. array_init(BG(active_ini_file_section));
  2509. if (is_numeric_string(Z_STRVAL_P(arg1), Z_STRLEN_P(arg1), NULL, NULL, 0) != IS_LONG) {
  2510. zend_hash_update(Z_ARRVAL_P(arr), Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, &BG(active_ini_file_section), sizeof(zval *), NULL);
  2511. } else {
  2512. ulong key = (ulong) zend_atoi(Z_STRVAL_P(arg1), Z_STRLEN_P(arg1));
  2513. zend_hash_index_update(Z_ARRVAL_P(arr), key, &BG(active_ini_file_section), sizeof(zval *), NULL);
  2514. }
  2515. } else if (arg2) {
  2516. zval *active_arr;
  2517. if (BG(active_ini_file_section)) {
  2518. active_arr = BG(active_ini_file_section);
  2519. } else {
  2520. active_arr = arr;
  2521. }
  2522. php_simple_ini_parser_cb(arg1, arg2, callback_type, active_arr);
  2523. }
  2524. }
  2525. /* {{{ proto array parse_ini_file(string filename [, bool process_sections])
  2526. Parse configuration file */
  2527. PHP_FUNCTION(parse_ini_file)
  2528. {
  2529. zval **filename, **process_sections;
  2530. zend_file_handle fh;
  2531. zend_ini_parser_cb_t ini_parser_cb;
  2532. switch (ZEND_NUM_ARGS()) {
  2533. case 1:
  2534. if (zend_get_parameters_ex(1, &filename) == FAILURE) {
  2535. RETURN_FALSE;
  2536. }
  2537. ini_parser_cb = (zend_ini_parser_cb_t) php_simple_ini_parser_cb;
  2538. break;
  2539. case 2:
  2540. if (zend_get_parameters_ex(2, &filename, &process_sections) == FAILURE) {
  2541. RETURN_FALSE;
  2542. }
  2543. convert_to_boolean_ex(process_sections);
  2544. if (Z_BVAL_PP(process_sections)) {
  2545. BG(active_ini_file_section) = NULL;
  2546. ini_parser_cb = (zend_ini_parser_cb_t) php_ini_parser_cb_with_sections;
  2547. } else {
  2548. ini_parser_cb = (zend_ini_parser_cb_t) php_simple_ini_parser_cb;
  2549. }
  2550. break;
  2551. default:
  2552. ZEND_WRONG_PARAM_COUNT();
  2553. break;
  2554. }
  2555. convert_to_string_ex(filename);
  2556. memset(&fh, 0, sizeof(fh));
  2557. fh.filename = Z_STRVAL_PP(filename);
  2558. Z_TYPE(fh) = ZEND_HANDLE_FILENAME;
  2559. array_init(return_value);
  2560. zend_parse_ini_file(&fh, 0, ini_parser_cb, return_value);
  2561. }
  2562. /* }}} */
  2563. static int copy_request_variable(void *pDest, int num_args, va_list args, zend_hash_key *hash_key)
  2564. {
  2565. char *prefix, *new_key;
  2566. uint prefix_len, new_key_len;
  2567. zval **var = (zval **) pDest;
  2568. TSRMLS_FETCH();
  2569. if (num_args != 2) {
  2570. return 0;
  2571. }
  2572. prefix = va_arg(args, char *);
  2573. prefix_len = va_arg(args, uint);
  2574. new_key_len = prefix_len + hash_key->nKeyLength;
  2575. new_key = (char *) emalloc(new_key_len);
  2576. memcpy(new_key, prefix, prefix_len);
  2577. memcpy(new_key+prefix_len, hash_key->arKey, hash_key->nKeyLength);
  2578. zend_hash_del(&EG(symbol_table), new_key, new_key_len);
  2579. ZEND_SET_SYMBOL_WITH_LENGTH(&EG(symbol_table), new_key, new_key_len, *var, (*var)->refcount+1, 0);
  2580. efree(new_key);
  2581. return 0;
  2582. }
  2583. /* {{{ proto bool import_request_variables(string types [, string prefix])
  2584. Import GET/POST/Cookie variables into the global scope */
  2585. PHP_FUNCTION(import_request_variables)
  2586. {
  2587. zval **z_types, **z_prefix;
  2588. char *types, *prefix;
  2589. uint prefix_len;
  2590. char *p;
  2591. switch (ZEND_NUM_ARGS()) {
  2592. case 1:
  2593. if (zend_get_parameters_ex(1, &z_types) == FAILURE) {
  2594. RETURN_FALSE;
  2595. }
  2596. prefix = "";
  2597. prefix_len = 0;
  2598. break;
  2599. case 2:
  2600. if (zend_get_parameters_ex(2, &z_types, &z_prefix) == FAILURE) {
  2601. RETURN_FALSE;
  2602. }
  2603. convert_to_string_ex(z_prefix);
  2604. prefix = Z_STRVAL_PP(z_prefix);
  2605. prefix_len = Z_STRLEN_PP(z_prefix);
  2606. break;
  2607. default:
  2608. ZEND_WRONG_PARAM_COUNT();
  2609. }
  2610. if (prefix_len == 0) {
  2611. php_error_docref(NULL TSRMLS_CC, E_NOTICE, "No prefix specified - possible security hazard");
  2612. }
  2613. convert_to_string_ex(z_types);
  2614. types = Z_STRVAL_PP(z_types);
  2615. for (p = types; p && *p; p++) {
  2616. switch (*p) {
  2617. case 'g':
  2618. case 'G':
  2619. zend_hash_apply_with_arguments(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_GET]), (apply_func_args_t) copy_request_variable, 2, prefix, prefix_len);
  2620. break;
  2621. case 'p':
  2622. case 'P':
  2623. zend_hash_apply_with_arguments(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_POST]), (apply_func_args_t) copy_request_variable, 2, prefix, prefix_len);
  2624. zend_hash_apply_with_arguments(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_FILES]), (apply_func_args_t) copy_request_variable, 2, prefix, prefix_len);
  2625. break;
  2626. case 'c':
  2627. case 'C':
  2628. zend_hash_apply_with_arguments(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_COOKIE]), (apply_func_args_t) copy_request_variable, 2, prefix, prefix_len);
  2629. break;
  2630. }
  2631. }
  2632. }
  2633. /* }}} */
  2634. /*
  2635. * Local variables:
  2636. * tab-width: 4
  2637. * c-basic-offset: 4
  2638. * End:
  2639. * vim600: fdm=marker
  2640. * vim: noet sw=4 ts=4
  2641. */