zend_ini.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Zend Engine |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1998-2018 Zend Technologies Ltd. (http://www.zend.com) |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 2.00 of the Zend 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.zend.com/license/2_00.txt. |
  11. | If you did not receive a copy of the Zend license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@zend.com so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Author: Zeev Suraski <zeev@php.net> |
  16. +----------------------------------------------------------------------+
  17. */
  18. #include "zend.h"
  19. #include "zend_sort.h"
  20. #include "zend_API.h"
  21. #include "zend_ini.h"
  22. #include "zend_alloc.h"
  23. #include "zend_operators.h"
  24. #include "zend_strtod.h"
  25. static HashTable *registered_zend_ini_directives;
  26. #define NO_VALUE_PLAINTEXT "no value"
  27. #define NO_VALUE_HTML "<i>no value</i>"
  28. /*
  29. * hash_apply functions
  30. */
  31. static int zend_remove_ini_entries(zval *el, void *arg) /* {{{ */
  32. {
  33. zend_ini_entry *ini_entry = (zend_ini_entry *)Z_PTR_P(el);
  34. int module_number = *(int *)arg;
  35. if (ini_entry->module_number == module_number) {
  36. return 1;
  37. } else {
  38. return 0;
  39. }
  40. }
  41. /* }}} */
  42. static int zend_restore_ini_entry_cb(zend_ini_entry *ini_entry, int stage) /* {{{ */
  43. {
  44. int result = FAILURE;
  45. if (ini_entry->modified) {
  46. if (ini_entry->on_modify) {
  47. zend_try {
  48. /* even if on_modify bails out, we have to continue on with restoring,
  49. since there can be allocated variables that would be freed on MM shutdown
  50. and would lead to memory corruption later ini entry is modified again */
  51. result = ini_entry->on_modify(ini_entry, ini_entry->orig_value, ini_entry->mh_arg1, ini_entry->mh_arg2, ini_entry->mh_arg3, stage);
  52. } zend_end_try();
  53. }
  54. if (stage == ZEND_INI_STAGE_RUNTIME && result == FAILURE) {
  55. /* runtime failure is OK */
  56. return 1;
  57. }
  58. if (ini_entry->value != ini_entry->orig_value) {
  59. zend_string_release(ini_entry->value);
  60. }
  61. ini_entry->value = ini_entry->orig_value;
  62. ini_entry->modifiable = ini_entry->orig_modifiable;
  63. ini_entry->modified = 0;
  64. ini_entry->orig_value = NULL;
  65. ini_entry->orig_modifiable = 0;
  66. }
  67. return 0;
  68. }
  69. /* }}} */
  70. static int zend_restore_ini_entry_wrapper(zval *el) /* {{{ */
  71. {
  72. zend_ini_entry *ini_entry = (zend_ini_entry *)Z_PTR_P(el);
  73. zend_restore_ini_entry_cb(ini_entry, ZEND_INI_STAGE_DEACTIVATE);
  74. return 1;
  75. }
  76. /* }}} */
  77. static void free_ini_entry(zval *zv) /* {{{ */
  78. {
  79. zend_ini_entry *entry = (zend_ini_entry*)Z_PTR_P(zv);
  80. zend_string_release_ex(entry->name, 1);
  81. if (entry->value) {
  82. zend_string_release(entry->value);
  83. }
  84. if (entry->orig_value) {
  85. zend_string_release_ex(entry->orig_value, 1);
  86. }
  87. free(entry);
  88. }
  89. /* }}} */
  90. /*
  91. * Startup / shutdown
  92. */
  93. ZEND_API int zend_ini_startup(void) /* {{{ */
  94. {
  95. registered_zend_ini_directives = (HashTable *) malloc(sizeof(HashTable));
  96. EG(ini_directives) = registered_zend_ini_directives;
  97. EG(modified_ini_directives) = NULL;
  98. EG(error_reporting_ini_entry) = NULL;
  99. zend_hash_init_ex(registered_zend_ini_directives, 128, NULL, free_ini_entry, 1, 0);
  100. return SUCCESS;
  101. }
  102. /* }}} */
  103. ZEND_API int zend_ini_shutdown(void) /* {{{ */
  104. {
  105. zend_ini_dtor(EG(ini_directives));
  106. return SUCCESS;
  107. }
  108. /* }}} */
  109. ZEND_API void zend_ini_dtor(HashTable *ini_directives) /* {{{ */
  110. {
  111. zend_hash_destroy(ini_directives);
  112. free(ini_directives);
  113. }
  114. /* }}} */
  115. ZEND_API int zend_ini_global_shutdown(void) /* {{{ */
  116. {
  117. zend_hash_destroy(registered_zend_ini_directives);
  118. free(registered_zend_ini_directives);
  119. return SUCCESS;
  120. }
  121. /* }}} */
  122. ZEND_API int zend_ini_deactivate(void) /* {{{ */
  123. {
  124. if (EG(modified_ini_directives)) {
  125. zend_hash_apply(EG(modified_ini_directives), zend_restore_ini_entry_wrapper);
  126. zend_hash_destroy(EG(modified_ini_directives));
  127. FREE_HASHTABLE(EG(modified_ini_directives));
  128. EG(modified_ini_directives) = NULL;
  129. }
  130. return SUCCESS;
  131. }
  132. /* }}} */
  133. #ifdef ZTS
  134. static void copy_ini_entry(zval *zv) /* {{{ */
  135. {
  136. zend_ini_entry *old_entry = (zend_ini_entry*)Z_PTR_P(zv);
  137. zend_ini_entry *new_entry = pemalloc(sizeof(zend_ini_entry), 1);
  138. Z_PTR_P(zv) = new_entry;
  139. memcpy(new_entry, old_entry, sizeof(zend_ini_entry));
  140. if (old_entry->name) {
  141. new_entry->name = zend_string_dup(old_entry->name, 1);
  142. }
  143. if (old_entry->value) {
  144. new_entry->value = zend_string_dup(old_entry->value, 1);
  145. }
  146. if (old_entry->orig_value) {
  147. new_entry->orig_value = zend_string_dup(old_entry->orig_value, 1);
  148. }
  149. }
  150. /* }}} */
  151. ZEND_API int zend_copy_ini_directives(void) /* {{{ */
  152. {
  153. EG(modified_ini_directives) = NULL;
  154. EG(error_reporting_ini_entry) = NULL;
  155. EG(ini_directives) = (HashTable *) malloc(sizeof(HashTable));
  156. zend_hash_init_ex(EG(ini_directives), registered_zend_ini_directives->nNumOfElements, NULL, free_ini_entry, 1, 0);
  157. zend_hash_copy(EG(ini_directives), registered_zend_ini_directives, copy_ini_entry);
  158. return SUCCESS;
  159. }
  160. /* }}} */
  161. #endif
  162. static int ini_key_compare(const void *a, const void *b) /* {{{ */
  163. {
  164. const Bucket *f;
  165. const Bucket *s;
  166. f = (const Bucket *) a;
  167. s = (const Bucket *) b;
  168. if (!f->key && !s->key) { /* both numeric */
  169. if (f->h > s->h) {
  170. return -1;
  171. } else if (f->h < s->h) {
  172. return 1;
  173. }
  174. return 0;
  175. } else if (!f->key) { /* f is numeric, s is not */
  176. return -1;
  177. } else if (!s->key) { /* s is numeric, f is not */
  178. return 1;
  179. } else { /* both strings */
  180. return zend_binary_strcasecmp(ZSTR_VAL(f->key), ZSTR_LEN(f->key), ZSTR_VAL(s->key), ZSTR_LEN(s->key));
  181. }
  182. }
  183. /* }}} */
  184. ZEND_API void zend_ini_sort_entries(void) /* {{{ */
  185. {
  186. zend_hash_sort(EG(ini_directives), ini_key_compare, 0);
  187. }
  188. /* }}} */
  189. /*
  190. * Registration / unregistration
  191. */
  192. ZEND_API int zend_register_ini_entries(const zend_ini_entry_def *ini_entry, int module_number) /* {{{ */
  193. {
  194. zend_ini_entry *p;
  195. zval *default_value;
  196. HashTable *directives = registered_zend_ini_directives;
  197. #ifdef ZTS
  198. /* if we are called during the request, eg: from dl(),
  199. * then we should not touch the global directives table,
  200. * and should update the per-(request|thread) version instead.
  201. * This solves two problems: one is that ini entries for dl()'d
  202. * extensions will now work, and the second is that updating the
  203. * global hash here from dl() is not mutex protected and can
  204. * lead to death.
  205. */
  206. if (directives != EG(ini_directives)) {
  207. directives = EG(ini_directives);
  208. }
  209. #endif
  210. while (ini_entry->name) {
  211. p = pemalloc(sizeof(zend_ini_entry), 1);
  212. p->name = zend_string_init_interned(ini_entry->name, ini_entry->name_length, 1);
  213. p->on_modify = ini_entry->on_modify;
  214. p->mh_arg1 = ini_entry->mh_arg1;
  215. p->mh_arg2 = ini_entry->mh_arg2;
  216. p->mh_arg3 = ini_entry->mh_arg3;
  217. p->value = NULL;
  218. p->orig_value = NULL;
  219. p->displayer = ini_entry->displayer;
  220. p->modifiable = ini_entry->modifiable;
  221. p->orig_modifiable = 0;
  222. p->modified = 0;
  223. p->module_number = module_number;
  224. if (zend_hash_add_ptr(directives, p->name, (void*)p) == NULL) {
  225. if (p->name) {
  226. zend_string_release_ex(p->name, 1);
  227. }
  228. zend_unregister_ini_entries(module_number);
  229. return FAILURE;
  230. }
  231. if (((default_value = zend_get_configuration_directive(p->name)) != NULL) &&
  232. (!p->on_modify || p->on_modify(p, Z_STR_P(default_value), p->mh_arg1, p->mh_arg2, p->mh_arg3, ZEND_INI_STAGE_STARTUP) == SUCCESS)) {
  233. p->value = zend_new_interned_string(zend_string_copy(Z_STR_P(default_value)));
  234. } else {
  235. p->value = ini_entry->value ?
  236. zend_string_init_interned(ini_entry->value, ini_entry->value_length, 1) : NULL;
  237. if (p->on_modify) {
  238. p->on_modify(p, p->value, p->mh_arg1, p->mh_arg2, p->mh_arg3, ZEND_INI_STAGE_STARTUP);
  239. }
  240. }
  241. ini_entry++;
  242. }
  243. return SUCCESS;
  244. }
  245. /* }}} */
  246. ZEND_API void zend_unregister_ini_entries(int module_number) /* {{{ */
  247. {
  248. zend_hash_apply_with_argument(registered_zend_ini_directives, zend_remove_ini_entries, (void *) &module_number);
  249. }
  250. /* }}} */
  251. #ifdef ZTS
  252. static int zend_ini_refresh_cache(zval *el, void *arg) /* {{{ */
  253. {
  254. zend_ini_entry *p = (zend_ini_entry *)Z_PTR_P(el);
  255. int stage = (int)(zend_intptr_t)arg;
  256. if (p->on_modify) {
  257. p->on_modify(p, p->value, p->mh_arg1, p->mh_arg2, p->mh_arg3, stage);
  258. }
  259. return 0;
  260. }
  261. /* }}} */
  262. ZEND_API void zend_ini_refresh_caches(int stage) /* {{{ */
  263. {
  264. zend_hash_apply_with_argument(EG(ini_directives), zend_ini_refresh_cache, (void *)(zend_intptr_t) stage);
  265. }
  266. /* }}} */
  267. #endif
  268. ZEND_API int zend_alter_ini_entry(zend_string *name, zend_string *new_value, int modify_type, int stage) /* {{{ */
  269. {
  270. return zend_alter_ini_entry_ex(name, new_value, modify_type, stage, 0);
  271. }
  272. /* }}} */
  273. ZEND_API int zend_alter_ini_entry_chars(zend_string *name, const char *value, size_t value_length, int modify_type, int stage) /* {{{ */
  274. {
  275. int ret;
  276. zend_string *new_value;
  277. new_value = zend_string_init(value, value_length, !(stage & ZEND_INI_STAGE_IN_REQUEST));
  278. ret = zend_alter_ini_entry_ex(name, new_value, modify_type, stage, 0);
  279. zend_string_release(new_value);
  280. return ret;
  281. }
  282. /* }}} */
  283. ZEND_API int zend_alter_ini_entry_chars_ex(zend_string *name, const char *value, size_t value_length, int modify_type, int stage, int force_change) /* {{{ */
  284. {
  285. int ret;
  286. zend_string *new_value;
  287. new_value = zend_string_init(value, value_length, !(stage & ZEND_INI_STAGE_IN_REQUEST));
  288. ret = zend_alter_ini_entry_ex(name, new_value, modify_type, stage, force_change);
  289. zend_string_release(new_value);
  290. return ret;
  291. }
  292. /* }}} */
  293. ZEND_API int zend_alter_ini_entry_ex(zend_string *name, zend_string *new_value, int modify_type, int stage, int force_change) /* {{{ */
  294. {
  295. zend_ini_entry *ini_entry;
  296. zend_string *duplicate;
  297. uint8_t modifiable;
  298. zend_bool modified;
  299. if ((ini_entry = zend_hash_find_ptr(EG(ini_directives), name)) == NULL) {
  300. return FAILURE;
  301. }
  302. modifiable = ini_entry->modifiable;
  303. modified = ini_entry->modified;
  304. if (stage == ZEND_INI_STAGE_ACTIVATE && modify_type == ZEND_INI_SYSTEM) {
  305. ini_entry->modifiable = ZEND_INI_SYSTEM;
  306. }
  307. if (!force_change) {
  308. if (!(ini_entry->modifiable & modify_type)) {
  309. return FAILURE;
  310. }
  311. }
  312. if (!EG(modified_ini_directives)) {
  313. ALLOC_HASHTABLE(EG(modified_ini_directives));
  314. zend_hash_init(EG(modified_ini_directives), 8, NULL, NULL, 0);
  315. }
  316. if (!modified) {
  317. ini_entry->orig_value = ini_entry->value;
  318. ini_entry->orig_modifiable = modifiable;
  319. ini_entry->modified = 1;
  320. zend_hash_add_ptr(EG(modified_ini_directives), ini_entry->name, ini_entry);
  321. }
  322. duplicate = zend_string_copy(new_value);
  323. if (!ini_entry->on_modify
  324. || ini_entry->on_modify(ini_entry, duplicate, ini_entry->mh_arg1, ini_entry->mh_arg2, ini_entry->mh_arg3, stage) == SUCCESS) {
  325. if (modified && ini_entry->orig_value != ini_entry->value) { /* we already changed the value, free the changed value */
  326. zend_string_release(ini_entry->value);
  327. }
  328. ini_entry->value = duplicate;
  329. } else {
  330. zend_string_release(duplicate);
  331. return FAILURE;
  332. }
  333. return SUCCESS;
  334. }
  335. /* }}} */
  336. ZEND_API int zend_restore_ini_entry(zend_string *name, int stage) /* {{{ */
  337. {
  338. zend_ini_entry *ini_entry;
  339. if ((ini_entry = zend_hash_find_ptr(EG(ini_directives), name)) == NULL ||
  340. (stage == ZEND_INI_STAGE_RUNTIME && (ini_entry->modifiable & ZEND_INI_USER) == 0)) {
  341. return FAILURE;
  342. }
  343. if (EG(modified_ini_directives)) {
  344. if (zend_restore_ini_entry_cb(ini_entry, stage) == 0) {
  345. zend_hash_del(EG(modified_ini_directives), name);
  346. } else {
  347. return FAILURE;
  348. }
  349. }
  350. return SUCCESS;
  351. }
  352. /* }}} */
  353. ZEND_API int zend_ini_register_displayer(char *name, uint32_t name_length, void (*displayer)(zend_ini_entry *ini_entry, int type)) /* {{{ */
  354. {
  355. zend_ini_entry *ini_entry;
  356. ini_entry = zend_hash_str_find_ptr(registered_zend_ini_directives, name, name_length);
  357. if (ini_entry == NULL) {
  358. return FAILURE;
  359. }
  360. ini_entry->displayer = displayer;
  361. return SUCCESS;
  362. }
  363. /* }}} */
  364. /*
  365. * Data retrieval
  366. */
  367. ZEND_API zend_long zend_ini_long(char *name, size_t name_length, int orig) /* {{{ */
  368. {
  369. zend_ini_entry *ini_entry;
  370. ini_entry = zend_hash_str_find_ptr(EG(ini_directives), name, name_length);
  371. if (ini_entry) {
  372. if (orig && ini_entry->modified) {
  373. return (ini_entry->orig_value ? ZEND_STRTOL(ZSTR_VAL(ini_entry->orig_value), NULL, 0) : 0);
  374. } else {
  375. return (ini_entry->value ? ZEND_STRTOL(ZSTR_VAL(ini_entry->value), NULL, 0) : 0);
  376. }
  377. }
  378. return 0;
  379. }
  380. /* }}} */
  381. ZEND_API double zend_ini_double(char *name, size_t name_length, int orig) /* {{{ */
  382. {
  383. zend_ini_entry *ini_entry;
  384. ini_entry = zend_hash_str_find_ptr(EG(ini_directives), name, name_length);
  385. if (ini_entry) {
  386. if (orig && ini_entry->modified) {
  387. return (double) (ini_entry->orig_value ? zend_strtod(ZSTR_VAL(ini_entry->orig_value), NULL) : 0.0);
  388. } else {
  389. return (double) (ini_entry->value ? zend_strtod(ZSTR_VAL(ini_entry->value), NULL) : 0.0);
  390. }
  391. }
  392. return 0.0;
  393. }
  394. /* }}} */
  395. ZEND_API char *zend_ini_string_ex(char *name, size_t name_length, int orig, zend_bool *exists) /* {{{ */
  396. {
  397. zend_ini_entry *ini_entry;
  398. ini_entry = zend_hash_str_find_ptr(EG(ini_directives), name, name_length);
  399. if (ini_entry) {
  400. if (exists) {
  401. *exists = 1;
  402. }
  403. if (orig && ini_entry->modified) {
  404. return ini_entry->orig_value ? ZSTR_VAL(ini_entry->orig_value) : NULL;
  405. } else {
  406. return ini_entry->value ? ZSTR_VAL(ini_entry->value) : NULL;
  407. }
  408. } else {
  409. if (exists) {
  410. *exists = 0;
  411. }
  412. return NULL;
  413. }
  414. }
  415. /* }}} */
  416. ZEND_API char *zend_ini_string(char *name, size_t name_length, int orig) /* {{{ */
  417. {
  418. zend_bool exists = 1;
  419. char *return_value;
  420. return_value = zend_ini_string_ex(name, name_length, orig, &exists);
  421. if (!exists) {
  422. return NULL;
  423. } else if (!return_value) {
  424. return_value = "";
  425. }
  426. return return_value;
  427. }
  428. /* }}} */
  429. ZEND_API zend_string *zend_ini_get_value(zend_string *name) /* {{{ */
  430. {
  431. zend_ini_entry *ini_entry;
  432. ini_entry = zend_hash_find_ptr(EG(ini_directives), name);
  433. if (ini_entry) {
  434. return ini_entry->value ? ini_entry->value : ZSTR_EMPTY_ALLOC();
  435. } else {
  436. return NULL;
  437. }
  438. }
  439. /* }}} */
  440. ZEND_API zend_bool zend_ini_parse_bool(zend_string *str)
  441. {
  442. if ((ZSTR_LEN(str) == 4 && strcasecmp(ZSTR_VAL(str), "true") == 0)
  443. || (ZSTR_LEN(str) == 3 && strcasecmp(ZSTR_VAL(str), "yes") == 0)
  444. || (ZSTR_LEN(str) == 2 && strcasecmp(ZSTR_VAL(str), "on") == 0)) {
  445. return 1;
  446. } else {
  447. return atoi(ZSTR_VAL(str)) != 0;
  448. }
  449. }
  450. #if TONY_20070307
  451. static void zend_ini_displayer_cb(zend_ini_entry *ini_entry, int type) /* {{{ */
  452. {
  453. if (ini_entry->displayer) {
  454. ini_entry->displayer(ini_entry, type);
  455. } else {
  456. char *display_string;
  457. uint32_t display_string_length;
  458. if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {
  459. if (ini_entry->orig_value) {
  460. display_string = ini_entry->orig_value;
  461. display_string_length = ini_entry->orig_value_length;
  462. } else {
  463. if (zend_uv.html_errors) {
  464. display_string = NO_VALUE_HTML;
  465. display_string_length = sizeof(NO_VALUE_HTML) - 1;
  466. } else {
  467. display_string = NO_VALUE_PLAINTEXT;
  468. display_string_length = sizeof(NO_VALUE_PLAINTEXT) - 1;
  469. }
  470. }
  471. } else if (ini_entry->value && ini_entry->value[0]) {
  472. display_string = ini_entry->value;
  473. display_string_length = ini_entry->value_length;
  474. } else {
  475. if (zend_uv.html_errors) {
  476. display_string = NO_VALUE_HTML;
  477. display_string_length = sizeof(NO_VALUE_HTML) - 1;
  478. } else {
  479. display_string = NO_VALUE_PLAINTEXT;
  480. display_string_length = sizeof(NO_VALUE_PLAINTEXT) - 1;
  481. }
  482. }
  483. ZEND_WRITE(display_string, display_string_length);
  484. }
  485. }
  486. /* }}} */
  487. #endif
  488. ZEND_INI_DISP(zend_ini_boolean_displayer_cb) /* {{{ */
  489. {
  490. int value;
  491. zend_string *tmp_value;
  492. if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {
  493. tmp_value = (ini_entry->orig_value ? ini_entry->orig_value : NULL );
  494. } else if (ini_entry->value) {
  495. tmp_value = ini_entry->value;
  496. } else {
  497. tmp_value = NULL;
  498. }
  499. if (tmp_value) {
  500. value = zend_ini_parse_bool(tmp_value);
  501. } else {
  502. value = 0;
  503. }
  504. if (value) {
  505. ZEND_PUTS("On");
  506. } else {
  507. ZEND_PUTS("Off");
  508. }
  509. }
  510. /* }}} */
  511. ZEND_INI_DISP(zend_ini_color_displayer_cb) /* {{{ */
  512. {
  513. char *value;
  514. if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {
  515. value = ZSTR_VAL(ini_entry->orig_value);
  516. } else if (ini_entry->value) {
  517. value = ZSTR_VAL(ini_entry->value);
  518. } else {
  519. value = NULL;
  520. }
  521. if (value) {
  522. if (zend_uv.html_errors) {
  523. zend_printf("<font style=\"color: %s\">%s</font>", value, value);
  524. } else {
  525. ZEND_PUTS(value);
  526. }
  527. } else {
  528. if (zend_uv.html_errors) {
  529. ZEND_PUTS(NO_VALUE_HTML);
  530. } else {
  531. ZEND_PUTS(NO_VALUE_PLAINTEXT);
  532. }
  533. }
  534. }
  535. /* }}} */
  536. ZEND_INI_DISP(display_link_numbers) /* {{{ */
  537. {
  538. char *value;
  539. if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {
  540. value = ZSTR_VAL(ini_entry->orig_value);
  541. } else if (ini_entry->value) {
  542. value = ZSTR_VAL(ini_entry->value);
  543. } else {
  544. value = NULL;
  545. }
  546. if (value) {
  547. if (atoi(value) == -1) {
  548. ZEND_PUTS("Unlimited");
  549. } else {
  550. zend_printf("%s", value);
  551. }
  552. }
  553. }
  554. /* }}} */
  555. /* Standard message handlers */
  556. ZEND_API ZEND_INI_MH(OnUpdateBool) /* {{{ */
  557. {
  558. zend_bool *p;
  559. #ifndef ZTS
  560. char *base = (char *) mh_arg2;
  561. #else
  562. char *base;
  563. base = (char *) ts_resource(*((int *) mh_arg2));
  564. #endif
  565. p = (zend_bool *) (base+(size_t) mh_arg1);
  566. *p = zend_ini_parse_bool(new_value);
  567. return SUCCESS;
  568. }
  569. /* }}} */
  570. ZEND_API ZEND_INI_MH(OnUpdateLong) /* {{{ */
  571. {
  572. zend_long *p;
  573. #ifndef ZTS
  574. char *base = (char *) mh_arg2;
  575. #else
  576. char *base;
  577. base = (char *) ts_resource(*((int *) mh_arg2));
  578. #endif
  579. p = (zend_long *) (base+(size_t) mh_arg1);
  580. *p = zend_atol(ZSTR_VAL(new_value), ZSTR_LEN(new_value));
  581. return SUCCESS;
  582. }
  583. /* }}} */
  584. ZEND_API ZEND_INI_MH(OnUpdateLongGEZero) /* {{{ */
  585. {
  586. zend_long *p, tmp;
  587. #ifndef ZTS
  588. char *base = (char *) mh_arg2;
  589. #else
  590. char *base;
  591. base = (char *) ts_resource(*((int *) mh_arg2));
  592. #endif
  593. tmp = zend_atol(ZSTR_VAL(new_value), ZSTR_LEN(new_value));
  594. if (tmp < 0) {
  595. return FAILURE;
  596. }
  597. p = (zend_long *) (base+(size_t) mh_arg1);
  598. *p = tmp;
  599. return SUCCESS;
  600. }
  601. /* }}} */
  602. ZEND_API ZEND_INI_MH(OnUpdateReal) /* {{{ */
  603. {
  604. double *p;
  605. #ifndef ZTS
  606. char *base = (char *) mh_arg2;
  607. #else
  608. char *base;
  609. base = (char *) ts_resource(*((int *) mh_arg2));
  610. #endif
  611. p = (double *) (base+(size_t) mh_arg1);
  612. *p = zend_strtod(ZSTR_VAL(new_value), NULL);
  613. return SUCCESS;
  614. }
  615. /* }}} */
  616. ZEND_API ZEND_INI_MH(OnUpdateString) /* {{{ */
  617. {
  618. char **p;
  619. #ifndef ZTS
  620. char *base = (char *) mh_arg2;
  621. #else
  622. char *base;
  623. base = (char *) ts_resource(*((int *) mh_arg2));
  624. #endif
  625. p = (char **) (base+(size_t) mh_arg1);
  626. *p = new_value ? ZSTR_VAL(new_value) : NULL;
  627. return SUCCESS;
  628. }
  629. /* }}} */
  630. ZEND_API ZEND_INI_MH(OnUpdateStringUnempty) /* {{{ */
  631. {
  632. char **p;
  633. #ifndef ZTS
  634. char *base = (char *) mh_arg2;
  635. #else
  636. char *base;
  637. base = (char *) ts_resource(*((int *) mh_arg2));
  638. #endif
  639. if (new_value && !ZSTR_VAL(new_value)[0]) {
  640. return FAILURE;
  641. }
  642. p = (char **) (base+(size_t) mh_arg1);
  643. *p = new_value ? ZSTR_VAL(new_value) : NULL;
  644. return SUCCESS;
  645. }
  646. /* }}} */
  647. /*
  648. * Local variables:
  649. * tab-width: 4
  650. * c-basic-offset: 4
  651. * indent-tabs-mode: t
  652. * End:
  653. * vim600: sw=4 ts=4 fdm=marker
  654. * vim<600: sw=4 ts=4
  655. */