1 : /*
2 : +----------------------------------------------------------------------+
3 : | Zend Engine |
4 : +----------------------------------------------------------------------+
5 : | Copyright (c) 1998-2009 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 : | Authors: Andi Gutmans <andi@zend.com> |
16 : | Zeev Suraski <zeev@zend.com> |
17 : | Andrei Zmievski <andrei@php.net> |
18 : +----------------------------------------------------------------------+
19 : */
20 :
21 : /* $Id: zend_API.c 288089 2009-09-05 19:01:06Z pajoye $ */
22 :
23 : #include "zend.h"
24 : #include "zend_execute.h"
25 : #include "zend_API.h"
26 : #include "zend_modules.h"
27 : #include "zend_constants.h"
28 :
29 : #ifdef HAVE_STDARG_H
30 : #include <stdarg.h>
31 : #endif
32 :
33 : /* these variables are true statics/globals, and have to be mutex'ed on every access */
34 : static int module_count=0;
35 : ZEND_API HashTable module_registry;
36 :
37 : /* this function doesn't check for too many parameters */
38 : ZEND_API int zend_get_parameters(int ht, int param_count, ...)
39 6 : {
40 : void **p;
41 : int arg_count;
42 : va_list ptr;
43 : zval **param, *param_ptr;
44 : TSRMLS_FETCH();
45 :
46 6 : p = EG(argument_stack).top_element-2;
47 6 : arg_count = (int)(zend_uintptr_t) *p;
48 :
49 6 : if (param_count>arg_count) {
50 0 : return FAILURE;
51 : }
52 :
53 6 : va_start(ptr, param_count);
54 :
55 18 : while (param_count-->0) {
56 6 : param = va_arg(ptr, zval **);
57 6 : param_ptr = *(p-arg_count);
58 6 : if (!PZVAL_IS_REF(param_ptr) && param_ptr->refcount>1) {
59 : zval *new_tmp;
60 :
61 0 : ALLOC_ZVAL(new_tmp);
62 0 : *new_tmp = *param_ptr;
63 0 : zval_copy_ctor(new_tmp);
64 0 : INIT_PZVAL(new_tmp);
65 0 : param_ptr = new_tmp;
66 0 : ((zval *) *(p-arg_count))->refcount--;
67 0 : *(p-arg_count) = param_ptr;
68 : }
69 6 : *param = param_ptr;
70 6 : arg_count--;
71 : }
72 6 : va_end(ptr);
73 :
74 6 : return SUCCESS;
75 : }
76 :
77 :
78 : ZEND_API int _zend_get_parameters_array(int ht, int param_count, zval **argument_array TSRMLS_DC)
79 17 : {
80 : void **p;
81 : int arg_count;
82 : zval *param_ptr;
83 :
84 17 : p = EG(argument_stack).top_element-2;
85 17 : arg_count = (int)(zend_uintptr_t) *p;
86 :
87 17 : if (param_count>arg_count) {
88 0 : return FAILURE;
89 : }
90 :
91 51 : while (param_count-->0) {
92 17 : param_ptr = *(p-arg_count);
93 17 : if (!PZVAL_IS_REF(param_ptr) && param_ptr->refcount>1) {
94 : zval *new_tmp;
95 :
96 0 : ALLOC_ZVAL(new_tmp);
97 0 : *new_tmp = *param_ptr;
98 0 : zval_copy_ctor(new_tmp);
99 0 : INIT_PZVAL(new_tmp);
100 0 : param_ptr = new_tmp;
101 0 : ((zval *) *(p-arg_count))->refcount--;
102 0 : *(p-arg_count) = param_ptr;
103 : }
104 17 : *(argument_array++) = param_ptr;
105 17 : arg_count--;
106 : }
107 :
108 17 : return SUCCESS;
109 : }
110 :
111 :
112 :
113 :
114 : /* Zend-optimized Extended functions */
115 : /* this function doesn't check for too many parameters */
116 : ZEND_API int zend_get_parameters_ex(int param_count, ...)
117 8076457 : {
118 : void **p;
119 : int arg_count;
120 : va_list ptr;
121 : zval ***param;
122 : TSRMLS_FETCH();
123 :
124 8076457 : p = EG(argument_stack).top_element-2;
125 8076457 : arg_count = (int)(zend_uintptr_t) *p;
126 :
127 8076457 : if (param_count>arg_count) {
128 2 : return FAILURE;
129 : }
130 :
131 8076455 : va_start(ptr, param_count);
132 28200313 : while (param_count-->0) {
133 12047403 : param = va_arg(ptr, zval ***);
134 12047403 : *param = (zval **) p-(arg_count--);
135 : }
136 8076455 : va_end(ptr);
137 :
138 8076455 : return SUCCESS;
139 : }
140 :
141 :
142 : ZEND_API int _zend_get_parameters_array_ex(int param_count, zval ***argument_array TSRMLS_DC)
143 187982 : {
144 : void **p;
145 : int arg_count;
146 :
147 187982 : p = EG(argument_stack).top_element-2;
148 187982 : arg_count = (int)(zend_uintptr_t) *p;
149 :
150 187982 : if (param_count>arg_count) {
151 0 : return FAILURE;
152 : }
153 :
154 635677 : while (param_count-->0) {
155 259714 : zval **value = (zval**)(p-arg_count);
156 :
157 259714 : if (EG(ze1_compatibility_mode) &&
158 : Z_TYPE_PP(value) == IS_OBJECT &&
159 : !(*value)->is_ref) {
160 : zval *value_ptr;
161 : char *class_name;
162 : zend_uint class_name_len;
163 : int dup;
164 :
165 4 : dup = zend_get_object_classname(*value, &class_name, &class_name_len TSRMLS_CC);
166 :
167 4 : ALLOC_ZVAL(value_ptr);
168 4 : *value_ptr = **value;
169 4 : INIT_PZVAL(value_ptr);
170 4 : zend_error(E_STRICT, "Implicit cloning object of class '%s' because of 'zend.ze1_compatibility_mode'", class_name);
171 :
172 4 : if (Z_OBJ_HANDLER_PP(value, clone_obj) == NULL) {
173 1 : zend_error(E_CORE_ERROR, "Trying to clone uncloneable object of class %s", class_name);
174 : }
175 :
176 3 : if(!dup) {
177 3 : efree(class_name);
178 : }
179 :
180 3 : value_ptr->value.obj = Z_OBJ_HANDLER_PP(value, clone_obj)(*value TSRMLS_CC);
181 3 : zval_ptr_dtor(value);
182 3 : *value = value_ptr;
183 : }
184 259713 : *(argument_array++) = value;
185 259713 : arg_count--;
186 : }
187 :
188 187981 : return SUCCESS;
189 : }
190 :
191 :
192 : ZEND_API int zend_copy_parameters_array(int param_count, zval *argument_array TSRMLS_DC)
193 379 : {
194 : void **p;
195 : int arg_count;
196 :
197 379 : p = EG(argument_stack).top_element-2;
198 379 : arg_count = (int)(zend_uintptr_t) *p;
199 :
200 379 : if (param_count>arg_count) {
201 0 : return FAILURE;
202 : }
203 :
204 1182 : while (param_count-->0) {
205 424 : zval **param = (zval **) p-(arg_count--);
206 424 : zval_add_ref(param);
207 424 : add_next_index_zval(argument_array, *param);
208 : }
209 :
210 379 : return SUCCESS;
211 : }
212 :
213 :
214 : ZEND_API void zend_wrong_param_count(TSRMLS_D)
215 1182 : {
216 : char *space;
217 1182 : char *class_name = get_active_class_name(&space TSRMLS_CC);
218 :
219 1182 : zend_error(E_WARNING, "Wrong parameter count for %s%s%s()", class_name, space, get_active_function_name(TSRMLS_C));
220 1182 : }
221 :
222 :
223 : /* Argument parsing API -- andrei */
224 :
225 : ZEND_API char *zend_get_type_by_const(int type)
226 4294 : {
227 4294 : switch(type) {
228 : case IS_BOOL:
229 247 : return "boolean";
230 : case IS_LONG:
231 272 : return "integer";
232 : case IS_DOUBLE:
233 264 : return "double";
234 : case IS_STRING:
235 1306 : return "string";
236 : case IS_OBJECT:
237 496 : return "object";
238 : case IS_RESOURCE:
239 272 : return "resource";
240 : case IS_NULL:
241 200 : return "null";
242 : case IS_ARRAY:
243 1237 : return "array";
244 : default:
245 0 : return "unknown";
246 : }
247 : }
248 :
249 : ZEND_API char *zend_zval_type_name(zval *arg)
250 4240 : {
251 4240 : return zend_get_type_by_const(Z_TYPE_P(arg));
252 : }
253 :
254 : ZEND_API zend_class_entry *zend_get_class_entry(zval *zobject TSRMLS_DC)
255 130631 : {
256 130631 : if (Z_OBJ_HT_P(zobject)->get_class_entry) {
257 130631 : return Z_OBJ_HT_P(zobject)->get_class_entry(zobject TSRMLS_CC);
258 : } else {
259 0 : zend_error(E_ERROR, "Class entry requested for an object without PHP class");
260 0 : return NULL;
261 : }
262 : }
263 :
264 : /* returns 1 if you need to copy result, 0 if it's already a copy */
265 : ZEND_API int zend_get_object_classname(zval *object, char **class_name, zend_uint *class_name_len TSRMLS_DC)
266 402 : {
267 402 : if (Z_OBJ_HT_P(object)->get_class_name == NULL ||
268 : Z_OBJ_HT_P(object)->get_class_name(object, class_name, class_name_len, 0 TSRMLS_CC) != SUCCESS) {
269 0 : zend_class_entry *ce = Z_OBJCE_P(object);
270 :
271 0 : *class_name = ce->name;
272 0 : *class_name_len = ce->name_length;
273 0 : return 1;
274 : }
275 402 : return 0;
276 : }
277 :
278 : static int parse_arg_object_to_string(zval **arg, char **p, int *pl, int type TSRMLS_DC)
279 200253 : {
280 200253 : if (Z_OBJ_HANDLER_PP(arg, cast_object)) {
281 200253 : SEPARATE_ZVAL_IF_NOT_REF(arg);
282 200253 : if (Z_OBJ_HANDLER_PP(arg, cast_object)(*arg, *arg, type TSRMLS_CC) == SUCCESS) {
283 200133 : *pl = Z_STRLEN_PP(arg);
284 200133 : *p = Z_STRVAL_PP(arg);
285 200133 : return SUCCESS;
286 : }
287 : }
288 : /* Standard PHP objects */
289 120 : if (Z_OBJ_HT_PP(arg) == &std_object_handlers || !Z_OBJ_HANDLER_PP(arg, cast_object)) {
290 120 : SEPARATE_ZVAL_IF_NOT_REF(arg);
291 120 : if (zend_std_cast_object_tostring(*arg, *arg, type TSRMLS_CC) == SUCCESS) {
292 0 : *pl = Z_STRLEN_PP(arg);
293 0 : *p = Z_STRVAL_PP(arg);
294 0 : return SUCCESS;
295 : }
296 : }
297 120 : if (!Z_OBJ_HANDLER_PP(arg, cast_object) && Z_OBJ_HANDLER_PP(arg, get)) {
298 : int use_copy;
299 0 : zval *z = Z_OBJ_HANDLER_PP(arg, get)(*arg TSRMLS_CC);
300 0 : z->refcount++;
301 0 : if(Z_TYPE_P(z) != IS_OBJECT) {
302 0 : zval_dtor(*arg);
303 0 : Z_TYPE_P(*arg) = IS_NULL;
304 0 : zend_make_printable_zval(z, *arg, &use_copy);
305 0 : if (!use_copy) {
306 0 : ZVAL_ZVAL(*arg, z, 1, 1);
307 : }
308 0 : *pl = Z_STRLEN_PP(arg);
309 0 : *p = Z_STRVAL_PP(arg);
310 0 : return SUCCESS;
311 : }
312 0 : zval_ptr_dtor(&z);
313 : }
314 120 : return FAILURE;
315 : }
316 :
317 : static char *zend_parse_arg_impl(int arg_num, zval **arg, va_list *va, char **spec TSRMLS_DC)
318 7826001 : {
319 7826001 : char *spec_walk = *spec;
320 7826001 : char c = *spec_walk++;
321 7826001 : int return_null = 0;
322 :
323 18392406 : while (*spec_walk == '/' || *spec_walk == '!') {
324 2740404 : if (*spec_walk == '/') {
325 227821 : SEPARATE_ZVAL_IF_NOT_REF(arg);
326 2512583 : } else if (*spec_walk == '!' && Z_TYPE_PP(arg) == IS_NULL) {
327 1228455 : return_null = 1;
328 : }
329 2740404 : spec_walk++;
330 : }
331 :
332 7826001 : switch (c) {
333 : case 'l':
334 : {
335 193018 : long *p = va_arg(*va, long *);
336 193018 : switch (Z_TYPE_PP(arg)) {
337 : case IS_STRING:
338 : {
339 : double d;
340 : int type;
341 :
342 1494 : if ((type = is_numeric_string(Z_STRVAL_PP(arg), Z_STRLEN_PP(arg), p, &d, -1)) == 0) {
343 878 : return "long";
344 616 : } else if (type == IS_DOUBLE) {
345 205 : *p = (long) d;
346 : }
347 : }
348 616 : break;
349 :
350 : case IS_NULL:
351 : case IS_LONG:
352 : case IS_DOUBLE:
353 : case IS_BOOL:
354 190812 : convert_to_long_ex(arg);
355 190812 : *p = Z_LVAL_PP(arg);
356 190812 : break;
357 :
358 : case IS_ARRAY:
359 : case IS_OBJECT:
360 : case IS_RESOURCE:
361 : default:
362 712 : return "long";
363 : }
364 : }
365 191428 : break;
366 :
367 : case 'd':
368 : {
369 3905 : double *p = va_arg(*va, double *);
370 3905 : switch (Z_TYPE_PP(arg)) {
371 : case IS_STRING:
372 : {
373 : long l;
374 : int type;
375 :
376 278 : if ((type = is_numeric_string(Z_STRVAL_PP(arg), Z_STRLEN_PP(arg), &l, p, -1)) == 0) {
377 189 : return "double";
378 89 : } else if (type == IS_LONG) {
379 31 : *p = (double) l;
380 : }
381 : }
382 89 : break;
383 :
384 : case IS_NULL:
385 : case IS_LONG:
386 : case IS_DOUBLE:
387 : case IS_BOOL:
388 3455 : convert_to_double_ex(arg);
389 3455 : *p = Z_DVAL_PP(arg);
390 3455 : break;
391 :
392 : case IS_ARRAY:
393 : case IS_OBJECT:
394 : case IS_RESOURCE:
395 : default:
396 172 : return "double";
397 : }
398 : }
399 3544 : break;
400 :
401 : case 's':
402 : {
403 3378576 : char **p = va_arg(*va, char **);
404 3378576 : int *pl = va_arg(*va, int *);
405 3378576 : switch (Z_TYPE_PP(arg)) {
406 : case IS_NULL:
407 2444 : if (return_null) {
408 759 : *p = NULL;
409 759 : *pl = 0;
410 759 : break;
411 : }
412 : /* break omitted intentionally */
413 :
414 : case IS_STRING:
415 : case IS_LONG:
416 : case IS_DOUBLE:
417 : case IS_BOOL:
418 3176897 : convert_to_string_ex(arg);
419 3176897 : *p = Z_STRVAL_PP(arg);
420 3176897 : *pl = Z_STRLEN_PP(arg);
421 3176897 : break;
422 :
423 : case IS_OBJECT:
424 200253 : if (parse_arg_object_to_string(arg, p, pl, IS_STRING TSRMLS_CC) == SUCCESS) {
425 200133 : break;
426 : }
427 :
428 : case IS_ARRAY:
429 : case IS_RESOURCE:
430 : default:
431 787 : return "string";
432 : }
433 : }
434 3377789 : break;
435 :
436 : case 'b':
437 : {
438 3563 : zend_bool *p = va_arg(*va, zend_bool *);
439 3563 : switch (Z_TYPE_PP(arg)) {
440 : case IS_NULL:
441 : case IS_STRING:
442 : case IS_LONG:
443 : case IS_DOUBLE:
444 : case IS_BOOL:
445 3449 : convert_to_boolean_ex(arg);
446 3449 : *p = Z_BVAL_PP(arg);
447 : break;
448 :
449 : case IS_ARRAY:
450 : case IS_OBJECT:
451 : case IS_RESOURCE:
452 : default:
453 114 : return "boolean";
454 : }
455 : }
456 3449 : break;
457 :
458 : case 'r':
459 : {
460 382757 : zval **p = va_arg(*va, zval **);
461 382757 : if (Z_TYPE_PP(arg) != IS_RESOURCE) {
462 472 : if (Z_TYPE_PP(arg) == IS_NULL && return_null) {
463 106 : *p = NULL;
464 : } else {
465 366 : return "resource";
466 : }
467 : } else {
468 382285 : *p = *arg;
469 : }
470 : }
471 382391 : break;
472 :
473 : case 'a':
474 : {
475 1976515 : zval **p = va_arg(*va, zval **);
476 1976515 : if (Z_TYPE_PP(arg) != IS_ARRAY) {
477 1228278 : if (Z_TYPE_PP(arg) == IS_NULL && return_null) {
478 1227569 : *p = NULL;
479 : } else {
480 709 : return "array";
481 : }
482 : } else {
483 748237 : *p = *arg;
484 : }
485 : }
486 1975806 : break;
487 :
488 : case 'h':
489 : {
490 6 : HashTable **p = va_arg(*va, HashTable **);
491 6 : if (Z_TYPE_PP(arg) != IS_ARRAY) {
492 0 : if (Z_TYPE_PP(arg) == IS_NULL && return_null) {
493 0 : *p = NULL;
494 : } else {
495 0 : return "array";
496 : }
497 : } else {
498 6 : *p = Z_ARRVAL_PP(arg);
499 : }
500 : }
501 6 : break;
502 :
503 : case 'o':
504 : {
505 323 : zval **p = va_arg(*va, zval **);
506 323 : if (Z_TYPE_PP(arg) != IS_OBJECT) {
507 20 : if (Z_TYPE_PP(arg) == IS_NULL && return_null) {
508 1 : *p = NULL;
509 : } else {
510 19 : return "object";
511 : }
512 : } else {
513 303 : *p = *arg;
514 : }
515 : }
516 304 : break;
517 :
518 : case 'O':
519 : {
520 2243 : zval **p = va_arg(*va, zval **);
521 2243 : zend_class_entry *ce = va_arg(*va, zend_class_entry *);
522 :
523 3997 : if (Z_TYPE_PP(arg) == IS_OBJECT &&
524 : (!ce || instanceof_function(Z_OBJCE_PP(arg), ce TSRMLS_CC))) {
525 1754 : *p = *arg;
526 : } else {
527 491 : if (Z_TYPE_PP(arg) == IS_NULL && return_null) {
528 2 : *p = NULL;
529 487 : } else if (ce) {
530 487 : return ce->name;
531 : } else {
532 0 : return "object";
533 : }
534 : }
535 : }
536 1756 : break;
537 :
538 : case 'C':
539 : {
540 19 : zend_class_entry **lookup, **pce = va_arg(*va, zend_class_entry **);
541 19 : zend_class_entry *ce_base = *pce;
542 :
543 19 : if (return_null && Z_TYPE_PP(arg) == IS_NULL) {
544 2 : *pce = NULL;
545 2 : break;
546 : }
547 17 : convert_to_string_ex(arg);
548 17 : if (zend_lookup_class(Z_STRVAL_PP(arg), Z_STRLEN_PP(arg), &lookup TSRMLS_CC) == FAILURE) {
549 3 : *pce = NULL;
550 : } else {
551 14 : *pce = *lookup;
552 : }
553 17 : if (ce_base) {
554 17 : if ((!*pce || !instanceof_function(*pce, ce_base TSRMLS_CC)) && !return_null) {
555 : char *space;
556 8 : char *class_name = get_active_class_name(&space TSRMLS_CC);
557 8 : zend_error(E_WARNING, "%s%s%s() expects parameter %d to be a class name derived from %s, '%s' given",
558 : class_name, space, get_active_function_name(TSRMLS_C),
559 : arg_num, ce_base->name, Z_STRVAL_PP(arg));
560 8 : *pce = NULL;
561 8 : return "";
562 : }
563 : }
564 9 : if (!*pce) {
565 : char *space;
566 0 : char *class_name = get_active_class_name(&space TSRMLS_CC);
567 0 : zend_error(E_WARNING, "%s%s%s() expects parameter %d to be a valid class name, '%s' given",
568 : class_name, space, get_active_function_name(TSRMLS_C),
569 : arg_num, Z_STRVAL_PP(arg));
570 0 : return "";
571 : }
572 9 : break;
573 :
574 : }
575 : break;
576 :
577 : case 'f':
578 : {
579 8 : zend_fcall_info *fci = va_arg(*va, zend_fcall_info *);
580 8 : zend_fcall_info_cache *fcc = va_arg(*va, zend_fcall_info_cache *);
581 :
582 8 : if (zend_fcall_info_init(*arg, fci, fcc TSRMLS_CC) == SUCCESS) {
583 7 : break;
584 1 : } else if (return_null) {
585 0 : fci->size = 0;
586 0 : fcc->initialized = 0;
587 0 : break;
588 : } else {
589 1 : return "function";
590 : }
591 : }
592 :
593 : case 'z':
594 : {
595 1266474 : zval **p = va_arg(*va, zval **);
596 1266489 : if (Z_TYPE_PP(arg) == IS_NULL && return_null) {
597 15 : *p = NULL;
598 : } else {
599 1266459 : *p = *arg;
600 : }
601 : }
602 1266474 : break;
603 : case 'Z':
604 : {
605 618594 : zval ***p = va_arg(*va, zval ***);
606 618595 : if (Z_TYPE_PP(arg) == IS_NULL && return_null) {
607 1 : *p = NULL;
608 : } else {
609 618593 : *p = arg;
610 : }
611 : }
612 618594 : break;
613 : default:
614 0 : return "unknown";
615 : }
616 :
617 7821559 : *spec = spec_walk;
618 :
619 7821559 : return NULL;
620 : }
621 :
622 : static int zend_parse_arg(int arg_num, zval **arg, va_list *va, char **spec, int quiet TSRMLS_DC)
623 7826001 : {
624 7826001 : char *expected_type = NULL;
625 :
626 7826001 : expected_type = zend_parse_arg_impl(arg_num, arg, va, spec TSRMLS_CC);
627 7826001 : if (expected_type) {
628 4442 : if (!quiet && *expected_type) {
629 : char *space;
630 4189 : char *class_name = get_active_class_name(&space TSRMLS_CC);
631 :
632 4189 : zend_error(E_WARNING, "%s%s%s() expects parameter %d to be %s, %s given",
633 : class_name, space, get_active_function_name(TSRMLS_C), arg_num, expected_type,
634 : zend_zval_type_name(*arg));
635 : }
636 4442 : return FAILURE;
637 : }
638 :
639 7821559 : return SUCCESS;
640 : }
641 :
642 : static int zend_parse_va_args(int num_args, char *type_spec, va_list *va, int flags TSRMLS_DC)
643 3348122 : {
644 : char *spec_walk;
645 : int c, i;
646 3348122 : int min_num_args = -1;
647 3348122 : int max_num_args = 0;
648 : zval **arg;
649 : void **p;
650 : int arg_count;
651 3348122 : int quiet = flags & ZEND_PARSE_PARAMS_QUIET;
652 :
653 21566178 : for (spec_walk = type_spec; *spec_walk; spec_walk++) {
654 18218056 : c = *spec_walk;
655 18218056 : switch (c) {
656 : case 'l': case 'd':
657 : case 's': case 'b':
658 : case 'r': case 'a':
659 : case 'o': case 'O':
660 : case 'z': case 'Z':
661 : case 'C': case 'h':
662 : case 'f':
663 12413893 : max_num_args++;
664 12413893 : break;
665 :
666 : case '|':
667 2948963 : min_num_args = max_num_args;
668 2948963 : break;
669 :
670 : case '/':
671 : case '!':
672 : /* Pass */
673 2855200 : break;
674 :
675 : default:
676 0 : if (!quiet) {
677 0 : zend_function *active_function = EG(function_state_ptr)->function;
678 0 : char *class_name = active_function->common.scope ? active_function->common.scope->name : "";
679 0 : zend_error(E_WARNING, "%s%s%s(): bad type specifier while parsing parameters",
680 : class_name,
681 : class_name[0] ? "::" : "",
682 : get_active_function_name(TSRMLS_C));
683 : }
684 0 : return FAILURE;
685 : }
686 : }
687 :
688 3348122 : if (min_num_args < 0) {
689 399159 : min_num_args = max_num_args;
690 : }
691 :
692 3348122 : if (num_args < min_num_args || num_args > max_num_args) {
693 3331 : if (!quiet) {
694 829 : zend_function *active_function = EG(function_state_ptr)->function;
695 829 : char *class_name = active_function->common.scope ? active_function->common.scope->name : "";
696 829 : zend_error(E_WARNING, "%s%s%s() expects %s %d parameter%s, %d given",
697 : class_name,
698 : class_name[0] ? "::" : "",
699 : get_active_function_name(TSRMLS_C),
700 : min_num_args == max_num_args ? "exactly" : num_args < min_num_args ? "at least" : "at most",
701 : num_args < min_num_args ? min_num_args : max_num_args,
702 : (num_args < min_num_args ? min_num_args : max_num_args) == 1 ? "" : "s",
703 : num_args);
704 : }
705 3331 : return FAILURE;
706 : }
707 :
708 3344791 : p = EG(argument_stack).top_element-2;
709 3344791 : arg_count = (int)(zend_uintptr_t) *p;
710 :
711 3344791 : if (num_args > arg_count) {
712 0 : zend_error(E_WARNING, "%s(): could not obtain parameters for parsing",
713 : get_active_function_name(TSRMLS_C));
714 0 : return FAILURE;
715 : }
716 :
717 3344791 : i = 0;
718 14511141 : while (num_args-- > 0) {
719 7826001 : arg = (zval **) p - (arg_count-i);
720 7826001 : if (*type_spec == '|') {
721 1000424 : type_spec++;
722 : }
723 7826001 : if (zend_parse_arg(i+1, arg, va, &type_spec, quiet TSRMLS_CC) == FAILURE) {
724 4442 : return FAILURE;
725 : }
726 7821559 : i++;
727 : }
728 :
729 3340349 : return SUCCESS;
730 : }
731 :
732 : ZEND_API int zend_parse_parameters_ex(int flags, int num_args TSRMLS_DC, char *type_spec, ...)
733 3527 : {
734 : va_list va;
735 : int retval;
736 :
737 3527 : va_start(va, type_spec);
738 3527 : retval = zend_parse_va_args(num_args, type_spec, &va, flags TSRMLS_CC);
739 3527 : va_end(va);
740 :
741 3527 : return retval;
742 : }
743 :
744 : ZEND_API int zend_parse_parameters(int num_args TSRMLS_DC, char *type_spec, ...)
745 3341239 : {
746 : va_list va;
747 : int retval;
748 :
749 3341239 : va_start(va, type_spec);
750 3341239 : retval = zend_parse_va_args(num_args, type_spec, &va, 0 TSRMLS_CC);
751 3341239 : va_end(va);
752 :
753 3341239 : return retval;
754 : }
755 :
756 : ZEND_API int zend_parse_method_parameters(int num_args TSRMLS_DC, zval *this_ptr, char *type_spec, ...)
757 3356 : {
758 : va_list va;
759 : int retval;
760 3356 : char *p = type_spec;
761 : zval **object;
762 : zend_class_entry *ce;
763 :
764 3356 : if (!this_ptr) {
765 1473 : va_start(va, type_spec);
766 1473 : retval = zend_parse_va_args(num_args, type_spec, &va, 0 TSRMLS_CC);
767 1473 : va_end(va);
768 : } else {
769 1883 : p++;
770 1883 : va_start(va, type_spec);
771 :
772 1883 : object = va_arg(va, zval **);
773 1883 : ce = va_arg(va, zend_class_entry *);
774 1883 : *object = this_ptr;
775 1883 : if (ce && !instanceof_function(Z_OBJCE_P(this_ptr), ce TSRMLS_CC)) {
776 0 : zend_error(E_CORE_ERROR, "%s::%s() must be derived from %s::%s",
777 : ce->name, get_active_function_name(TSRMLS_C), Z_OBJCE_P(this_ptr)->name, get_active_function_name(TSRMLS_C));
778 : }
779 :
780 1883 : retval = zend_parse_va_args(num_args, p, &va, 0 TSRMLS_CC);
781 1883 : va_end(va);
782 : }
783 3356 : return retval;
784 : }
785 :
786 :
787 : ZEND_API int zend_parse_method_parameters_ex(int flags, int num_args TSRMLS_DC, zval *this_ptr, char *type_spec, ...)
788 0 : {
789 : va_list va;
790 : int retval;
791 0 : char *p = type_spec;
792 : zval **object;
793 : zend_class_entry *ce;
794 0 : int quiet = flags & ZEND_PARSE_PARAMS_QUIET;
795 :
796 0 : if (!this_ptr) {
797 0 : va_start(va, type_spec);
798 0 : retval = zend_parse_va_args(num_args, type_spec, &va, 0 TSRMLS_CC);
799 0 : va_end(va);
800 : } else {
801 0 : p++;
802 0 : va_start(va, type_spec);
803 :
804 0 : object = va_arg(va, zval **);
805 0 : ce = va_arg(va, zend_class_entry *);
806 0 : *object = this_ptr;
807 0 : if (ce && !instanceof_function(Z_OBJCE_P(this_ptr), ce TSRMLS_CC)) {
808 0 : if (!quiet) {
809 0 : zend_error(E_CORE_ERROR, "%s::%s() must be derived from %s::%s",
810 : ce->name, get_active_function_name(TSRMLS_C), Z_OBJCE_P(this_ptr)->name, get_active_function_name(TSRMLS_C));
811 : }
812 0 : return FAILURE;
813 : }
814 :
815 0 : retval = zend_parse_va_args(num_args, p, &va, flags TSRMLS_CC);
816 0 : va_end(va);
817 : }
818 0 : return retval;
819 : }
820 :
821 :
822 : /* Argument parsing API -- andrei */
823 :
824 :
825 : ZEND_API int _array_init(zval *arg ZEND_FILE_LINE_DC)
826 1917596 : {
827 1917596 : ALLOC_HASHTABLE_REL(arg->value.ht);
828 :
829 1917596 : _zend_hash_init(arg->value.ht, 0, NULL, ZVAL_PTR_DTOR, 0 ZEND_FILE_LINE_RELAY_CC);
830 1917596 : arg->type = IS_ARRAY;
831 1917596 : return SUCCESS;
832 : }
833 :
834 :
835 : static int zend_merge_property(zval **value, int num_args, va_list args, zend_hash_key *hash_key)
836 74 : {
837 : /* which name should a numeric property have ? */
838 74 : if (hash_key->nKeyLength) {
839 74 : zval *obj = va_arg(args, zval *);
840 74 : zend_object_handlers *obj_ht = va_arg(args, zend_object_handlers *);
841 : zval *member;
842 : TSRMLS_FETCH();
843 :
844 74 : MAKE_STD_ZVAL(member);
845 74 : ZVAL_STRINGL(member, hash_key->arKey, hash_key->nKeyLength-1, 1);
846 74 : obj_ht->write_property(obj, member, *value TSRMLS_CC);
847 74 : zval_ptr_dtor(&member);
848 : }
849 74 : return ZEND_HASH_APPLY_KEEP;
850 : }
851 :
852 :
853 : /* This function should be called after the constructor has been called
854 : * because it may call __set from the uninitialized object otherwise. */
855 : ZEND_API void zend_merge_properties(zval *obj, HashTable *properties, int destroy_ht TSRMLS_DC)
856 34 : {
857 34 : zend_object_handlers *obj_ht = Z_OBJ_HT_P(obj);
858 34 : zend_class_entry *old_scope = EG(scope);
859 :
860 34 : EG(scope) = Z_OBJCE_P(obj);
861 34 : zend_hash_apply_with_arguments(properties, (apply_func_args_t)zend_merge_property, 2, obj, obj_ht);
862 34 : EG(scope) = old_scope;
863 :
864 34 : if (destroy_ht) {
865 34 : zend_hash_destroy(properties);
866 34 : FREE_HASHTABLE(properties);
867 : }
868 34 : }
869 :
870 :
871 : ZEND_API void zend_update_class_constants(zend_class_entry *class_type TSRMLS_DC)
872 459345 : {
873 459345 : if (!class_type->constants_updated || !CE_STATIC_MEMBERS(class_type)) {
874 8360 : zend_class_entry **scope = EG(in_execution)?&EG(scope):&CG(active_class_entry);
875 8360 : zend_class_entry *old_scope = *scope;
876 :
877 8360 : *scope = class_type;
878 8360 : zend_hash_apply_with_argument(&class_type->constants_table, (apply_func_arg_t) zval_update_constant, (void*)1 TSRMLS_CC);
879 8359 : zend_hash_apply_with_argument(&class_type->default_properties, (apply_func_arg_t) zval_update_constant, (void *) 1 TSRMLS_CC);
880 :
881 8359 : if (!CE_STATIC_MEMBERS(class_type)) {
882 : HashPosition pos;
883 : zval **p;
884 :
885 5625 : if (class_type->parent) {
886 1167 : zend_update_class_constants(class_type->parent TSRMLS_CC);
887 : }
888 : #if ZTS
889 : ALLOC_HASHTABLE(CG(static_members)[(zend_intptr_t)(class_type->static_members)]);
890 : #else
891 5625 : ALLOC_HASHTABLE(class_type->static_members);
892 : #endif
893 5625 : zend_hash_init(CE_STATIC_MEMBERS(class_type), zend_hash_num_elements(&class_type->default_static_members), NULL, ZVAL_PTR_DTOR, 0);
894 :
895 5625 : zend_hash_internal_pointer_reset_ex(&class_type->default_static_members, &pos);
896 11250 : while (zend_hash_get_current_data_ex(&class_type->default_static_members, (void**)&p, &pos) == SUCCESS) {
897 : char *str_index;
898 : uint str_length;
899 : ulong num_index;
900 : zval **q;
901 :
902 0 : zend_hash_get_current_key_ex(&class_type->default_static_members, &str_index, &str_length, &num_index, 0, &pos);
903 0 : if ((*p)->is_ref &&
904 : class_type->parent &&
905 : zend_hash_find(&class_type->parent->default_static_members, str_index, str_length, (void**)&q) == SUCCESS &&
906 : *p == *q &&
907 : zend_hash_find(CE_STATIC_MEMBERS(class_type->parent), str_index, str_length, (void**)&q) == SUCCESS) {
908 0 : (*q)->refcount++;
909 0 : (*q)->is_ref = 1;
910 0 : zend_hash_add(CE_STATIC_MEMBERS(class_type), str_index, str_length, (void**)q, sizeof(zval*), NULL);
911 : } else {
912 : zval *r;
913 :
914 0 : ALLOC_ZVAL(r);
915 0 : *r = **p;
916 0 : INIT_PZVAL(r);
917 0 : zval_copy_ctor(r);
918 0 : zend_hash_add(CE_STATIC_MEMBERS(class_type), str_index, str_length, (void**)&r, sizeof(zval*), NULL);
919 : }
920 0 : zend_hash_move_forward_ex(&class_type->default_static_members, &pos);
921 : }
922 : }
923 8359 : zend_hash_apply_with_argument(CE_STATIC_MEMBERS(class_type), (apply_func_arg_t) zval_update_constant, (void *) 1 TSRMLS_CC);
924 :
925 8359 : *scope = old_scope;
926 8359 : class_type->constants_updated = 1;
927 : }
928 459344 : }
929 :
930 :
931 : /* This function requires 'properties' to contain all props declared in the
932 : * class and all props being public. If only a subset is given or the class
933 : * has protected members then you need to merge the properties seperately by
934 : * calling zend_merge_properties(). */
935 : ZEND_API int _object_and_properties_init(zval *arg, zend_class_entry *class_type, HashTable *properties ZEND_FILE_LINE_DC TSRMLS_DC)
936 457233 : {
937 : zval *tmp;
938 : zend_object *object;
939 :
940 457233 : if (class_type->ce_flags & (ZEND_ACC_INTERFACE|ZEND_ACC_IMPLICIT_ABSTRACT_CLASS|ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)) {
941 0 : char *what = class_type->ce_flags & ZEND_ACC_INTERFACE ? "interface" : "abstract class";
942 0 : zend_error(E_ERROR, "Cannot instantiate %s %s", what, class_type->name);
943 : }
944 :
945 457233 : zend_update_class_constants(class_type TSRMLS_CC);
946 :
947 457232 : Z_TYPE_P(arg) = IS_OBJECT;
948 457232 : if (class_type->create_object == NULL) {
949 451081 : Z_OBJVAL_P(arg) = zend_objects_new(&object, class_type TSRMLS_CC);
950 451081 : if (properties) {
951 70 : object->properties = properties;
952 : } else {
953 451011 : ALLOC_HASHTABLE_REL(object->properties);
954 451011 : zend_hash_init(object->properties, zend_hash_num_elements(&class_type->default_properties), NULL, ZVAL_PTR_DTOR, 0);
955 451011 : zend_hash_copy(object->properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
956 : }
957 : } else {
958 6151 : Z_OBJVAL_P(arg) = class_type->create_object(class_type TSRMLS_CC);
959 : }
960 457232 : return SUCCESS;
961 : }
962 :
963 : ZEND_API int _object_init_ex(zval *arg, zend_class_entry *class_type ZEND_FILE_LINE_DC TSRMLS_DC)
964 457099 : {
965 457099 : return _object_and_properties_init(arg, class_type, 0 ZEND_FILE_LINE_RELAY_CC TSRMLS_CC);
966 : }
967 :
968 : ZEND_API int _object_init(zval *arg ZEND_FILE_LINE_DC TSRMLS_DC)
969 367 : {
970 367 : return _object_init_ex(arg, zend_standard_class_def ZEND_FILE_LINE_RELAY_CC TSRMLS_CC);
971 : }
972 :
973 :
974 : ZEND_API int add_assoc_function(zval *arg, char *key, void (*function_ptr)(INTERNAL_FUNCTION_PARAMETERS))
975 0 : {
976 0 : zend_error(E_WARNING, "add_assoc_function() is no longer supported");
977 0 : return FAILURE;
978 : }
979 :
980 :
981 : ZEND_API int add_assoc_long_ex(zval *arg, char *key, uint key_len, long n)
982 73208 : {
983 : zval *tmp;
984 :
985 73208 : MAKE_STD_ZVAL(tmp);
986 73208 : ZVAL_LONG(tmp, n);
987 :
988 73208 : return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), NULL);
989 : }
990 :
991 : ZEND_API int add_assoc_null_ex(zval *arg, char *key, uint key_len)
992 350 : {
993 : zval *tmp;
994 :
995 350 : MAKE_STD_ZVAL(tmp);
996 350 : ZVAL_NULL(tmp);
997 :
998 350 : return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), NULL);
999 : }
1000 :
1001 : ZEND_API int add_assoc_bool_ex(zval *arg, char *key, uint key_len, int b)
1002 47205 : {
1003 : zval *tmp;
1004 :
1005 47205 : MAKE_STD_ZVAL(tmp);
1006 47205 : ZVAL_BOOL(tmp, b);
1007 :
1008 47205 : return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), NULL);
1009 : }
1010 :
1011 : ZEND_API int add_assoc_resource_ex(zval *arg, char *key, uint key_len, int r)
1012 30 : {
1013 : zval *tmp;
1014 :
1015 30 : MAKE_STD_ZVAL(tmp);
1016 30 : ZVAL_RESOURCE(tmp, r);
1017 :
1018 30 : return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), NULL);
1019 : }
1020 :
1021 :
1022 : ZEND_API int add_assoc_double_ex(zval *arg, char *key, uint key_len, double d)
1023 176 : {
1024 : zval *tmp;
1025 :
1026 176 : MAKE_STD_ZVAL(tmp);
1027 176 : ZVAL_DOUBLE(tmp, d);
1028 :
1029 176 : return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), NULL);
1030 : }
1031 :
1032 :
1033 : ZEND_API int add_assoc_string_ex(zval *arg, char *key, uint key_len, char *str, int duplicate)
1034 29828 : {
1035 : zval *tmp;
1036 :
1037 29828 : MAKE_STD_ZVAL(tmp);
1038 29828 : ZVAL_STRING(tmp, str, duplicate);
1039 :
1040 29828 : return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), NULL);
1041 : }
1042 :
1043 :
1044 : ZEND_API int add_assoc_stringl_ex(zval *arg, char *key, uint key_len, char *str, uint length, int duplicate)
1045 2628 : {
1046 : zval *tmp;
1047 :
1048 2628 : MAKE_STD_ZVAL(tmp);
1049 2628 : ZVAL_STRINGL(tmp, str, length, duplicate);
1050 :
1051 2628 : return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), NULL);
1052 : }
1053 :
1054 : ZEND_API int add_assoc_zval_ex(zval *arg, char *key, uint key_len, zval *value)
1055 208036 : {
1056 208036 : return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &value, sizeof(zval *), NULL);
1057 : }
1058 :
1059 :
1060 : ZEND_API int add_index_long(zval *arg, ulong index, long n)
1061 13219 : {
1062 : zval *tmp;
1063 :
1064 13219 : MAKE_STD_ZVAL(tmp);
1065 13219 : ZVAL_LONG(tmp, n);
1066 :
1067 13219 : return zend_hash_index_update(Z_ARRVAL_P(arg), index, (void *) &tmp, sizeof(zval *), NULL);
1068 : }
1069 :
1070 :
1071 : ZEND_API int add_index_null(zval *arg, ulong index)
1072 11287 : {
1073 : zval *tmp;
1074 :
1075 11287 : MAKE_STD_ZVAL(tmp);
1076 11287 : ZVAL_NULL(tmp);
1077 :
1078 11287 : return zend_hash_index_update(Z_ARRVAL_P(arg), index, (void *) &tmp, sizeof(zval *), NULL);
1079 : }
1080 :
1081 : ZEND_API int add_index_bool(zval *arg, ulong index, int b)
1082 76 : {
1083 : zval *tmp;
1084 :
1085 76 : MAKE_STD_ZVAL(tmp);
1086 76 : ZVAL_BOOL(tmp, b);
1087 :
1088 76 : return zend_hash_index_update(Z_ARRVAL_P(arg), index, (void *) &tmp, sizeof(zval *), NULL);
1089 : }
1090 :
1091 :
1092 : ZEND_API int add_index_resource(zval *arg, ulong index, int r)
1093 34 : {
1094 : zval *tmp;
1095 :
1096 34 : MAKE_STD_ZVAL(tmp);
1097 34 : ZVAL_RESOURCE(tmp, r);
1098 :
1099 34 : return zend_hash_index_update(Z_ARRVAL_P(arg), index, (void *) &tmp, sizeof(zval *), NULL);
1100 : }
1101 :
1102 :
1103 : ZEND_API int add_index_double(zval *arg, ulong index, double d)
1104 1007 : {
1105 : zval *tmp;
1106 :
1107 1007 : MAKE_STD_ZVAL(tmp);
1108 1007 : ZVAL_DOUBLE(tmp, d);
1109 :
1110 1007 : return zend_hash_index_update(Z_ARRVAL_P(arg), index, (void *) &tmp, sizeof(zval *), NULL);
1111 : }
1112 :
1113 :
1114 : ZEND_API int add_index_string(zval *arg, ulong index, char *str, int duplicate)
1115 773 : {
1116 : zval *tmp;
1117 :
1118 773 : MAKE_STD_ZVAL(tmp);
1119 773 : ZVAL_STRING(tmp, str, duplicate);
1120 :
1121 773 : return zend_hash_index_update(Z_ARRVAL_P(arg), index, (void *) &tmp, sizeof(zval *), NULL);
1122 : }
1123 :
1124 :
1125 : ZEND_API int add_index_stringl(zval *arg, ulong index, char *str, uint length, int duplicate)
1126 30529 : {
1127 : zval *tmp;
1128 :
1129 30529 : MAKE_STD_ZVAL(tmp);
1130 30529 : ZVAL_STRINGL(tmp, str, length, duplicate);
1131 :
1132 30529 : return zend_hash_index_update(Z_ARRVAL_P(arg), index, (void *) &tmp, sizeof(zval *), NULL);
1133 : }
1134 :
1135 :
1136 : ZEND_API int add_index_zval(zval *arg, ulong index, zval *value)
1137 51390 : {
1138 51390 : return zend_hash_index_update(Z_ARRVAL_P(arg), index, (void *) &value, sizeof(zval *), NULL);
1139 : }
1140 :
1141 :
1142 : ZEND_API int add_next_index_long(zval *arg, long n)
1143 374160 : {
1144 : zval *tmp;
1145 :
1146 374160 : MAKE_STD_ZVAL(tmp);
1147 374160 : ZVAL_LONG(tmp, n);
1148 :
1149 374160 : return zend_hash_next_index_insert(Z_ARRVAL_P(arg), &tmp, sizeof(zval *), NULL);
1150 : }
1151 :
1152 :
1153 : ZEND_API int add_next_index_null(zval *arg)
1154 36 : {
1155 : zval *tmp;
1156 :
1157 36 : MAKE_STD_ZVAL(tmp);
1158 36 : ZVAL_NULL(tmp);
1159 :
1160 36 : return zend_hash_next_index_insert(Z_ARRVAL_P(arg), &tmp, sizeof(zval *), NULL);
1161 : }
1162 :
1163 :
1164 : ZEND_API int add_next_index_bool(zval *arg, int b)
1165 0 : {
1166 : zval *tmp;
1167 :
1168 0 : MAKE_STD_ZVAL(tmp);
1169 0 : ZVAL_BOOL(tmp, b);
1170 :
1171 0 : return zend_hash_next_index_insert(Z_ARRVAL_P(arg), &tmp, sizeof(zval *), NULL);
1172 : }
1173 :
1174 :
1175 : ZEND_API int add_next_index_resource(zval *arg, int r)
1176 12 : {
1177 : zval *tmp;
1178 :
1179 12 : MAKE_STD_ZVAL(tmp);
1180 12 : ZVAL_RESOURCE(tmp, r);
1181 :
1182 12 : return zend_hash_next_index_insert(Z_ARRVAL_P(arg), &tmp, sizeof(zval *), NULL);
1183 : }
1184 :
1185 :
1186 : ZEND_API int add_next_index_double(zval *arg, double d)
1187 241 : {
1188 : zval *tmp;
1189 :
1190 241 : MAKE_STD_ZVAL(tmp);
1191 241 : ZVAL_DOUBLE(tmp, d);
1192 :
1193 241 : return zend_hash_next_index_insert(Z_ARRVAL_P(arg), &tmp, sizeof(zval *), NULL);
1194 : }
1195 :
1196 :
1197 : ZEND_API int add_next_index_string(zval *arg, char *str, int duplicate)
1198 5449 : {
1199 : zval *tmp;
1200 :
1201 5449 : MAKE_STD_ZVAL(tmp);
1202 5449 : ZVAL_STRING(tmp, str, duplicate);
1203 :
1204 5449 : return zend_hash_next_index_insert(Z_ARRVAL_P(arg), &tmp, sizeof(zval *), NULL);
1205 : }
1206 :
1207 :
1208 : ZEND_API int add_next_index_stringl(zval *arg, char *str, uint length, int duplicate)
1209 847894 : {
1210 : zval *tmp;
1211 :
1212 847894 : MAKE_STD_ZVAL(tmp);
1213 847894 : ZVAL_STRINGL(tmp, str, length, duplicate);
1214 :
1215 847894 : return zend_hash_next_index_insert(Z_ARRVAL_P(arg), &tmp, sizeof(zval *), NULL);
1216 : }
1217 :
1218 :
1219 : ZEND_API int add_next_index_zval(zval *arg, zval *value)
1220 25171 : {
1221 25171 : return zend_hash_next_index_insert(Z_ARRVAL_P(arg), &value, sizeof(zval *), NULL);
1222 : }
1223 :
1224 :
1225 : ZEND_API int add_get_assoc_string_ex(zval *arg, char *key, uint key_len, char *str, void **dest, int duplicate)
1226 0 : {
1227 : zval *tmp;
1228 :
1229 0 : MAKE_STD_ZVAL(tmp);
1230 0 : ZVAL_STRING(tmp, str, duplicate);
1231 :
1232 0 : return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), dest);
1233 : }
1234 :
1235 :
1236 : ZEND_API int add_get_assoc_stringl_ex(zval *arg, char *key, uint key_len, char *str, uint length, void **dest, int duplicate)
1237 0 : {
1238 : zval *tmp;
1239 :
1240 0 : MAKE_STD_ZVAL(tmp);
1241 0 : ZVAL_STRINGL(tmp, str, length, duplicate);
1242 :
1243 0 : return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), dest);
1244 : }
1245 :
1246 :
1247 : ZEND_API int add_get_index_long(zval *arg, ulong index, long l, void **dest)
1248 114 : {
1249 : zval *tmp;
1250 :
1251 114 : MAKE_STD_ZVAL(tmp);
1252 114 : ZVAL_LONG(tmp, l);
1253 :
1254 114 : return zend_hash_index_update(Z_ARRVAL_P(arg), index, (void *) &tmp, sizeof(zval *), dest);
1255 : }
1256 :
1257 :
1258 : ZEND_API int add_get_index_double(zval *arg, ulong index, double d, void **dest)
1259 0 : {
1260 : zval *tmp;
1261 :
1262 0 : MAKE_STD_ZVAL(tmp);
1263 0 : ZVAL_DOUBLE(tmp, d);
1264 :
1265 0 : return zend_hash_index_update(Z_ARRVAL_P(arg), index, (void *) &tmp, sizeof(zval *), dest);
1266 : }
1267 :
1268 :
1269 : ZEND_API int add_get_index_string(zval *arg, ulong index, char *str, void **dest, int duplicate)
1270 0 : {
1271 : zval *tmp;
1272 :
1273 0 : MAKE_STD_ZVAL(tmp);
1274 0 : ZVAL_STRING(tmp, str, duplicate);
1275 :
1276 0 : return zend_hash_index_update(Z_ARRVAL_P(arg), index, (void *) &tmp, sizeof(zval *), dest);
1277 : }
1278 :
1279 :
1280 : ZEND_API int add_get_index_stringl(zval *arg, ulong index, char *str, uint length, void **dest, int duplicate)
1281 35 : {
1282 : zval *tmp;
1283 :
1284 35 : MAKE_STD_ZVAL(tmp);
1285 35 : ZVAL_STRINGL(tmp, str, length, duplicate);
1286 :
1287 35 : return zend_hash_index_update(Z_ARRVAL_P(arg), index, (void *) &tmp, sizeof(zval *), dest);
1288 : }
1289 :
1290 :
1291 : ZEND_API int add_property_long_ex(zval *arg, char *key, uint key_len, long n TSRMLS_DC)
1292 1265 : {
1293 : zval *tmp;
1294 : zval *z_key;
1295 :
1296 1265 : MAKE_STD_ZVAL(tmp);
1297 1265 : ZVAL_LONG(tmp, n);
1298 :
1299 1265 : MAKE_STD_ZVAL(z_key);
1300 1265 : ZVAL_STRINGL(z_key, key, key_len-1, 1);
1301 :
1302 1265 : Z_OBJ_HANDLER_P(arg, write_property)(arg, z_key, tmp TSRMLS_CC);
1303 1265 : zval_ptr_dtor(&tmp); /* write_property will add 1 to refcount */
1304 1265 : zval_ptr_dtor(&z_key);
1305 1265 : return SUCCESS;
1306 : }
1307 :
1308 : ZEND_API int add_property_bool_ex(zval *arg, char *key, uint key_len, int b TSRMLS_DC)
1309 345 : {
1310 : zval *tmp;
1311 : zval *z_key;
1312 :
1313 345 : MAKE_STD_ZVAL(tmp);
1314 345 : ZVAL_BOOL(tmp, b);
1315 :
1316 345 : MAKE_STD_ZVAL(z_key);
1317 345 : ZVAL_STRINGL(z_key, key, key_len-1, 1);
1318 :
1319 345 : Z_OBJ_HANDLER_P(arg, write_property)(arg, z_key, tmp TSRMLS_CC);
1320 345 : zval_ptr_dtor(&tmp); /* write_property will add 1 to refcount */
1321 345 : zval_ptr_dtor(&z_key);
1322 345 : return SUCCESS;
1323 : }
1324 :
1325 : ZEND_API int add_property_null_ex(zval *arg, char *key, uint key_len TSRMLS_DC)
1326 62 : {
1327 : zval *tmp;
1328 : zval *z_key;
1329 :
1330 62 : MAKE_STD_ZVAL(tmp);
1331 62 : ZVAL_NULL(tmp);
1332 :
1333 62 : MAKE_STD_ZVAL(z_key);
1334 62 : ZVAL_STRINGL(z_key, key, key_len-1, 1);
1335 :
1336 62 : Z_OBJ_HANDLER_P(arg, write_property)(arg, z_key, tmp TSRMLS_CC);
1337 62 : zval_ptr_dtor(&tmp); /* write_property will add 1 to refcount */
1338 62 : zval_ptr_dtor(&z_key);
1339 62 : return SUCCESS;
1340 : }
1341 :
1342 : ZEND_API int add_property_resource_ex(zval *arg, char *key, uint key_len, long n TSRMLS_DC)
1343 343298 : {
1344 : zval *tmp;
1345 : zval *z_key;
1346 :
1347 343298 : MAKE_STD_ZVAL(tmp);
1348 343298 : ZVAL_RESOURCE(tmp, n);
1349 :
1350 343298 : MAKE_STD_ZVAL(z_key);
1351 343298 : ZVAL_STRINGL(z_key, key, key_len-1, 1);
1352 :
1353 343298 : Z_OBJ_HANDLER_P(arg, write_property)(arg, z_key, tmp TSRMLS_CC);
1354 343298 : zval_ptr_dtor(&tmp); /* write_property will add 1 to refcount */
1355 343298 : zval_ptr_dtor(&z_key);
1356 343298 : return SUCCESS;
1357 : }
1358 :
1359 :
1360 : ZEND_API int add_property_double_ex(zval *arg, char *key, uint key_len, double d TSRMLS_DC)
1361 0 : {
1362 : zval *tmp;
1363 : zval *z_key;
1364 :
1365 0 : MAKE_STD_ZVAL(tmp);
1366 0 : ZVAL_DOUBLE(tmp, d);
1367 :
1368 0 : MAKE_STD_ZVAL(z_key);
1369 0 : ZVAL_STRINGL(z_key, key, key_len-1, 1);
1370 :
1371 0 : Z_OBJ_HANDLER_P(arg, write_property)(arg, z_key, tmp TSRMLS_CC);
1372 0 : zval_ptr_dtor(&tmp); /* write_property will add 1 to refcount */
1373 0 : zval_ptr_dtor(&z_key);
1374 0 : return SUCCESS;
1375 : }
1376 :
1377 :
1378 : ZEND_API int add_property_string_ex(zval *arg, char *key, uint key_len, char *str, int duplicate TSRMLS_DC)
1379 1349 : {
1380 : zval *tmp;
1381 : zval *z_key;
1382 :
1383 1349 : MAKE_STD_ZVAL(tmp);
1384 1349 : ZVAL_STRING(tmp, str, duplicate);
1385 :
1386 1349 : MAKE_STD_ZVAL(z_key);
1387 1349 : ZVAL_STRINGL(z_key, key, key_len-1, 1);
1388 :
1389 1349 : Z_OBJ_HANDLER_P(arg, write_property)(arg, z_key, tmp TSRMLS_CC);
1390 1349 : zval_ptr_dtor(&tmp); /* write_property will add 1 to refcount */
1391 1349 : zval_ptr_dtor(&z_key);
1392 1349 : return SUCCESS;
1393 : }
1394 :
1395 : ZEND_API int add_property_stringl_ex(zval *arg, char *key, uint key_len, char *str, uint length, int duplicate TSRMLS_DC)
1396 724 : {
1397 : zval *tmp;
1398 : zval *z_key;
1399 :
1400 724 : MAKE_STD_ZVAL(tmp);
1401 724 : ZVAL_STRINGL(tmp, str, length, duplicate);
1402 :
1403 724 : MAKE_STD_ZVAL(z_key);
1404 724 : ZVAL_STRINGL(z_key, key, key_len-1, 1);
1405 :
1406 724 : Z_OBJ_HANDLER_P(arg, write_property)(arg, z_key, tmp TSRMLS_CC);
1407 724 : zval_ptr_dtor(&tmp); /* write_property will add 1 to refcount */
1408 724 : zval_ptr_dtor(&z_key);
1409 724 : return SUCCESS;
1410 : }
1411 :
1412 : ZEND_API int add_property_zval_ex(zval *arg, char *key, uint key_len, zval *value TSRMLS_DC)
1413 2099 : {
1414 : zval *z_key;
1415 :
1416 2099 : MAKE_STD_ZVAL(z_key);
1417 2099 : ZVAL_STRINGL(z_key, key, key_len-1, 1);
1418 :
1419 2099 : Z_OBJ_HANDLER_P(arg, write_property)(arg, z_key, value TSRMLS_CC);
1420 2099 : zval_ptr_dtor(&z_key);
1421 2099 : return SUCCESS;
1422 : }
1423 :
1424 : ZEND_API int zend_startup_module_ex(zend_module_entry *module TSRMLS_DC)
1425 813998 : {
1426 : int name_len;
1427 : char *lcname;
1428 :
1429 813998 : if (module->module_started) {
1430 0 : return SUCCESS;
1431 : }
1432 813998 : module->module_started = 1;
1433 :
1434 : /* Check module dependencies */
1435 813998 : if (module->deps) {
1436 230605 : zend_module_dep *dep = module->deps;
1437 :
1438 759640 : while (dep->name) {
1439 298430 : if (dep->type == MODULE_DEP_REQUIRED) {
1440 : zend_module_entry *req_mod;
1441 :
1442 257735 : name_len = strlen(dep->name);
1443 257735 : lcname = zend_str_tolower_dup(dep->name, name_len);
1444 :
1445 257735 : if (zend_hash_find(&module_registry, lcname, name_len+1, (void**)&req_mod) == FAILURE ||
1446 : !req_mod->module_started) {
1447 0 : efree(lcname);
1448 : /* TODO: Check version relationship */
1449 0 : zend_error(E_CORE_WARNING, "Cannot load module '%s' because required module '%s' is not loaded", module->name, dep->name);
1450 0 : module->module_started = 0;
1451 0 : return FAILURE;
1452 : }
1453 257735 : efree(lcname);
1454 : }
1455 298430 : ++dep;
1456 : }
1457 : }
1458 :
1459 : /* Initialize module globals */
1460 813998 : if (module->globals_size) {
1461 : #ifdef ZTS
1462 : ts_allocate_id(module->globals_id_ptr, module->globals_size, (ts_allocate_ctor) module->globals_ctor, (ts_allocate_dtor) module->globals_dtor);
1463 : #else
1464 366255 : if (module->globals_ctor) {
1465 325560 : module->globals_ctor(module->globals_ptr TSRMLS_CC);
1466 : }
1467 : #endif
1468 : }
1469 :
1470 813998 : if (module->module_startup_func) {
1471 786868 : EG(current_module) = module;
1472 786868 : if (module->module_startup_func(module->type, module->module_number TSRMLS_CC)==FAILURE) {
1473 0 : zend_error(E_CORE_ERROR,"Unable to start %s module", module->name);
1474 0 : EG(current_module) = NULL;
1475 0 : return FAILURE;
1476 : }
1477 786868 : EG(current_module) = NULL;
1478 : }
1479 813998 : return SUCCESS;
1480 : }
1481 :
1482 : static void zend_sort_modules(void *base, size_t count, size_t siz, compare_func_t compare TSRMLS_DC)
1483 13565 : {
1484 13565 : Bucket **b1 = base;
1485 : Bucket **b2;
1486 13565 : Bucket **end = b1 + count;
1487 : Bucket *tmp;
1488 : zend_module_entry *m, *r;
1489 :
1490 841128 : while (b1 < end) {
1491 908953 : try_again:
1492 908953 : m = (zend_module_entry*)(*b1)->pData;
1493 908953 : if (!m->module_started && m->deps) {
1494 325560 : zend_module_dep *dep = m->deps;
1495 963115 : while (dep->name) {
1496 406950 : if (dep->type == MODULE_DEP_REQUIRED || dep->type == MODULE_DEP_OPTIONAL) {
1497 393385 : b2 = b1 + 1;
1498 8941491 : while (b2 < end) {
1499 8249676 : r = (zend_module_entry*)(*b2)->pData;
1500 8249676 : if (strcasecmp(dep->name, r->name) == 0) {
1501 94955 : tmp = *b1;
1502 94955 : *b1 = *b2;
1503 94955 : *b2 = tmp;
1504 94955 : goto try_again;
1505 : }
1506 8154721 : b2++;
1507 : }
1508 : }
1509 311995 : dep++;
1510 : }
1511 : }
1512 813998 : b1++;
1513 : }
1514 13565 : }
1515 :
1516 : ZEND_API int zend_startup_modules(TSRMLS_D)
1517 13565 : {
1518 13565 : zend_hash_sort(&module_registry, zend_sort_modules, NULL, 0 TSRMLS_CC);
1519 13565 : zend_hash_apply(&module_registry, (apply_func_t)zend_startup_module_ex TSRMLS_CC);
1520 13565 : return SUCCESS;
1521 : }
1522 :
1523 : ZEND_API zend_module_entry* zend_register_module_ex(zend_module_entry *module TSRMLS_DC)
1524 813998 : {
1525 : int name_len;
1526 : char *lcname;
1527 : zend_module_entry *module_ptr;
1528 :
1529 813998 : if (!module) {
1530 0 : return NULL;
1531 : }
1532 :
1533 : #if 0
1534 : zend_printf("%s: Registering module %d\n", module->name, module->module_number);
1535 : #endif
1536 :
1537 : /* Check module dependencies */
1538 813998 : if (module->deps) {
1539 230605 : zend_module_dep *dep = module->deps;
1540 :
1541 759640 : while (dep->name) {
1542 298430 : if (dep->type == MODULE_DEP_CONFLICTS) {
1543 13565 : name_len = strlen(dep->name);
1544 13565 : lcname = zend_str_tolower_dup(dep->name, name_len);
1545 :
1546 13565 : if (zend_hash_exists(&module_registry, lcname, name_len+1)) {
1547 0 : efree(lcname);
1548 : /* TODO: Check version relationship */
1549 0 : zend_error(E_CORE_WARNING, "Cannot load module '%s' because conflicting module '%s' is already loaded", module->name, dep->name);
1550 0 : return NULL;
1551 : }
1552 13565 : efree(lcname);
1553 : }
1554 298430 : ++dep;
1555 : }
1556 : }
1557 :
1558 813998 : name_len = strlen(module->name);
1559 813998 : lcname = zend_str_tolower_dup(module->name, name_len);
1560 :
1561 813998 : if (zend_hash_add(&module_registry, lcname, name_len+1, (void *)module, sizeof(zend_module_entry), (void**)&module_ptr)==FAILURE) {
1562 0 : zend_error(E_CORE_WARNING, "Module '%s' already loaded", module->name);
1563 0 : efree(lcname);
1564 0 : return NULL;
1565 : }
1566 813998 : efree(lcname);
1567 813998 : module = module_ptr;
1568 813998 : EG(current_module) = module;
1569 :
1570 813998 : if (module->functions && zend_register_functions(NULL, module->functions, NULL, module->type TSRMLS_CC)==FAILURE) {
1571 0 : EG(current_module) = NULL;
1572 0 : zend_error(E_CORE_WARNING,"%s: Unable to register functions, unable to load", module->name);
1573 0 : return NULL;
1574 : }
1575 :
1576 813998 : EG(current_module) = NULL;
1577 813998 : return module;
1578 : }
1579 :
1580 : ZEND_API zend_module_entry* zend_register_internal_module(zend_module_entry *module TSRMLS_DC)
1581 813998 : {
1582 813998 : module->module_number = zend_next_free_module();
1583 813998 : module->type = MODULE_PERSISTENT;
1584 813998 : return zend_register_module_ex(module TSRMLS_CC);
1585 : }
1586 :
1587 : ZEND_API void zend_check_magic_method_implementation(zend_class_entry *ce, zend_function *fptr, int error_type TSRMLS_DC)
1588 1041395 : {
1589 : char lcname[16];
1590 : int name_len;
1591 :
1592 : /* we don't care if the function name is longer, in fact lowercasing only
1593 : * the beginning of the name speeds up the check process */
1594 1041395 : name_len = strlen(fptr->common.function_name);
1595 1041395 : zend_str_tolower_copy(lcname, fptr->common.function_name, MIN(name_len, sizeof(lcname)-1));
1596 1041395 : lcname[sizeof(lcname)-1] = '\0'; /* zend_str_tolower_copy won't necessarily set the zero byte */
1597 :
1598 1041395 : if (name_len == sizeof(ZEND_DESTRUCTOR_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_DESTRUCTOR_FUNC_NAME, sizeof(ZEND_DESTRUCTOR_FUNC_NAME)) && fptr->common.num_args != 0) {
1599 1 : zend_error(error_type, "Destructor %s::%s() cannot take arguments", ce->name, ZEND_DESTRUCTOR_FUNC_NAME);
1600 1041394 : } else if (name_len == sizeof(ZEND_CLONE_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_CLONE_FUNC_NAME, sizeof(ZEND_CLONE_FUNC_NAME)) && fptr->common.num_args != 0) {
1601 1 : zend_error(error_type, "Method %s::%s() cannot accept any arguments", ce->name, ZEND_CLONE_FUNC_NAME);
1602 1041437 : } else if (name_len == sizeof(ZEND_GET_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_GET_FUNC_NAME, sizeof(ZEND_GET_FUNC_NAME))) {
1603 46 : if (fptr->common.num_args != 1) {
1604 1 : zend_error(error_type, "Method %s::%s() must take exactly 1 argument", ce->name, ZEND_GET_FUNC_NAME);
1605 45 : } else if (ARG_SHOULD_BE_SENT_BY_REF(fptr, 1)) {
1606 1 : zend_error(error_type, "Method %s::%s() cannot take arguments by reference", ce->name, ZEND_GET_FUNC_NAME);
1607 : }
1608 1041384 : } else if (name_len == sizeof(ZEND_SET_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_SET_FUNC_NAME, sizeof(ZEND_SET_FUNC_NAME))) {
1609 40 : if (fptr->common.num_args != 2) {
1610 1 : zend_error(error_type, "Method %s::%s() must take exactly 2 arguments", ce->name, ZEND_SET_FUNC_NAME);
1611 39 : } else if (ARG_SHOULD_BE_SENT_BY_REF(fptr, 1) || ARG_SHOULD_BE_SENT_BY_REF(fptr, 2)) {
1612 2 : zend_error(error_type, "Method %s::%s() cannot take arguments by reference", ce->name, ZEND_SET_FUNC_NAME);
1613 : }
1614 1041317 : } else if (name_len == sizeof(ZEND_UNSET_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_UNSET_FUNC_NAME, sizeof(ZEND_UNSET_FUNC_NAME))) {
1615 12 : if (fptr->common.num_args != 1) {
1616 1 : zend_error(error_type, "Method %s::%s() must take exactly 1 argument", ce->name, ZEND_UNSET_FUNC_NAME);
1617 11 : } else if (ARG_SHOULD_BE_SENT_BY_REF(fptr, 1)) {
1618 1 : zend_error(error_type, "Method %s::%s() cannot take arguments by reference", ce->name, ZEND_UNSET_FUNC_NAME);
1619 : }
1620 1041303 : } else if (name_len == sizeof(ZEND_ISSET_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_ISSET_FUNC_NAME, sizeof(ZEND_ISSET_FUNC_NAME))) {
1621 10 : if (fptr->common.num_args != 1) {
1622 1 : zend_error(error_type, "Method %s::%s() must take exactly 1 argument", ce->name, ZEND_ISSET_FUNC_NAME);
1623 9 : } else if (ARG_SHOULD_BE_SENT_BY_REF(fptr, 1)) {
1624 1 : zend_error(error_type, "Method %s::%s() cannot take arguments by reference", ce->name, ZEND_ISSET_FUNC_NAME);
1625 : }
1626 1041285 : } else if (name_len == sizeof(ZEND_CALL_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_CALL_FUNC_NAME, sizeof(ZEND_CALL_FUNC_NAME))) {
1627 13606 : if (fptr->common.num_args != 2) {
1628 1 : zend_error(error_type, "Method %s::%s() must take exactly 2 arguments", ce->name, ZEND_CALL_FUNC_NAME);
1629 13605 : } else if (ARG_SHOULD_BE_SENT_BY_REF(fptr, 1) || ARG_SHOULD_BE_SENT_BY_REF(fptr, 2)) {
1630 2 : zend_error(error_type, "Method %s::%s() cannot take arguments by reference", ce->name, ZEND_CALL_FUNC_NAME);
1631 : }
1632 : }
1633 1041381 : }
1634 :
1635 : /* registers all functions in *library_functions in the function hash */
1636 : ZEND_API int zend_register_functions(zend_class_entry *scope, zend_function_entry *functions, HashTable *function_table, int type TSRMLS_DC)
1637 2292489 : {
1638 2292489 : zend_function_entry *ptr = functions;
1639 : zend_function function, *reg_function;
1640 2292489 : zend_internal_function *internal_function = (zend_internal_function *)&function;
1641 2292489 : int count=0, unload=0;
1642 2292489 : HashTable *target_function_table = function_table;
1643 : int error_type;
1644 2292489 : zend_function *ctor = NULL, *dtor = NULL, *clone = NULL, *__get = NULL, *__set = NULL, *__unset = NULL, *__isset = NULL, *__call = NULL, *__tostring = NULL;
1645 : char *lowercase_name;
1646 : int fname_len;
1647 2292489 : char *lc_class_name = NULL;
1648 2292489 : int class_name_len = 0;
1649 :
1650 2292489 : if (type==MODULE_PERSISTENT) {
1651 2292489 : error_type = E_CORE_WARNING;
1652 : } else {
1653 0 : error_type = E_WARNING;
1654 : }
1655 :
1656 2292489 : if (!target_function_table) {
1657 813900 : target_function_table = CG(function_table);
1658 : }
1659 2292489 : internal_function->type = ZEND_INTERNAL_FUNCTION;
1660 2292489 : internal_function->module = EG(current_module);
1661 :
1662 2292489 : if (scope) {
1663 1478586 : class_name_len = strlen(scope->name);
1664 1478586 : lc_class_name = zend_str_tolower_dup(scope->name, class_name_len);
1665 : }
1666 :
1667 44981551 : while (ptr->fname) {
1668 40396573 : internal_function->handler = ptr->handler;
1669 40396573 : internal_function->function_name = ptr->fname;
1670 40396573 : internal_function->scope = scope;
1671 40396573 : internal_function->prototype = NULL;
1672 40396573 : if (ptr->arg_info) {
1673 16101655 : internal_function->arg_info = ptr->arg_info+1;
1674 16101655 : internal_function->num_args = ptr->num_args;
1675 : /* Currently you cannot denote that the function can accept less arguments than num_args */
1676 16101655 : if (ptr->arg_info[0].required_num_args == -1) {
1677 9292025 : internal_function->required_num_args = ptr->num_args;
1678 : } else {
1679 6809630 : internal_function->required_num_args = ptr->arg_info[0].required_num_args;
1680 : }
1681 16101655 : internal_function->pass_rest_by_reference = ptr->arg_info[0].pass_by_reference;
1682 16101655 : internal_function->return_reference = ptr->arg_info[0].return_reference;
1683 : } else {
1684 24294918 : internal_function->arg_info = NULL;
1685 24294918 : internal_function->num_args = 0;
1686 24294918 : internal_function->required_num_args = 0;
1687 24294918 : internal_function->pass_rest_by_reference = 0;
1688 24294918 : internal_function->return_reference = 0;
1689 : }
1690 40396573 : if (ptr->flags) {
1691 5670170 : if (!(ptr->flags & ZEND_ACC_PPP_MASK)) {
1692 81390 : if (ptr->flags != ZEND_ACC_DEPRECATED || scope) {
1693 0 : zend_error(error_type, "Invalid access level for %s%s%s() - access must be exactly one of public, protected or private", scope ? scope->name : "", scope ? "::" : "", ptr->fname);
1694 : }
1695 81390 : internal_function->fn_flags = ZEND_ACC_PUBLIC | ptr->flags;
1696 : } else {
1697 5588780 : internal_function->fn_flags = ptr->flags;
1698 : }
1699 : } else {
1700 34726403 : internal_function->fn_flags = ZEND_ACC_PUBLIC;
1701 : }
1702 40396573 : if (ptr->flags & ZEND_ACC_ABSTRACT) {
1703 339125 : if (scope) {
1704 : /* This is a class that must be abstract itself. Here we set the check info. */
1705 339125 : scope->ce_flags |= ZEND_ACC_IMPLICIT_ABSTRACT_CLASS;
1706 339125 : if (!(scope->ce_flags & ZEND_ACC_INTERFACE)) {
1707 : /* Since the class is not an interface it needs to be declared as a abstract class. */
1708 : /* Since here we are handling internal functions only we can add the keyword flag. */
1709 : /* This time we set the flag for the keyword 'abstract'. */
1710 27130 : scope->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS;
1711 : }
1712 : }
1713 339125 : if (ptr->flags & ZEND_ACC_STATIC && (!scope || !(scope->ce_flags & ZEND_ACC_INTERFACE))) {
1714 0 : zend_error(error_type, "Static function %s%s%s() cannot be abstract", scope ? scope->name : "", scope ? "::" : "", ptr->fname);
1715 : }
1716 : } else {
1717 40057448 : if (scope && (scope->ce_flags & ZEND_ACC_INTERFACE)) {
1718 0 : efree(lc_class_name);
1719 0 : zend_error(error_type, "Interface %s cannot contain non abstract method %s()", scope->name, ptr->fname);
1720 0 : return FAILURE;
1721 : }
1722 40057448 : if (!internal_function->handler) {
1723 0 : if (scope) {
1724 0 : efree(lc_class_name);
1725 : }
1726 0 : zend_error(error_type, "Method %s%s%s() cannot be a NULL function", scope ? scope->name : "", scope ? "::" : "", ptr->fname);
1727 0 : zend_unregister_functions(functions, count, target_function_table TSRMLS_CC);
1728 0 : return FAILURE;
1729 : }
1730 : }
1731 40396573 : fname_len = strlen(ptr->fname);
1732 40396573 : lowercase_name = zend_str_tolower_dup(ptr->fname, fname_len);
1733 40396573 : if (zend_hash_add(target_function_table, lowercase_name, fname_len+1, &function, sizeof(zend_function), (void**)®_function) == FAILURE) {
1734 0 : unload=1;
1735 0 : efree(lowercase_name);
1736 0 : break;
1737 : }
1738 40396573 : if (scope) {
1739 : /* Look for ctor, dtor, clone
1740 : * If it's an old-style constructor, store it only if we don't have
1741 : * a constructor already.
1742 : */
1743 12452670 : if ((fname_len == class_name_len) && !memcmp(lowercase_name, lc_class_name, class_name_len+1) && !ctor) {
1744 122085 : ctor = reg_function;
1745 12832490 : } else if ((fname_len == sizeof(ZEND_CONSTRUCTOR_FUNC_NAME)-1) && !memcmp(lowercase_name, ZEND_CONSTRUCTOR_FUNC_NAME, sizeof(ZEND_CONSTRUCTOR_FUNC_NAME))) {
1746 623990 : ctor = reg_function;
1747 11584510 : } else if ((fname_len == sizeof(ZEND_DESTRUCTOR_FUNC_NAME)-1) && !memcmp(lowercase_name, ZEND_DESTRUCTOR_FUNC_NAME, sizeof(ZEND_DESTRUCTOR_FUNC_NAME))) {
1748 0 : dtor = reg_function;
1749 0 : if (internal_function->num_args) {
1750 0 : zend_error(error_type, "Destructor %s::%s() cannot take arguments", scope->name, ptr->fname);
1751 : }
1752 11665900 : } else if ((fname_len == sizeof(ZEND_CLONE_FUNC_NAME)-1) && !memcmp(lowercase_name, ZEND_CLONE_FUNC_NAME, sizeof(ZEND_CLONE_FUNC_NAME))) {
1753 81390 : clone = reg_function;
1754 11516685 : } else if ((fname_len == sizeof(ZEND_CALL_FUNC_NAME)-1) && !memcmp(lowercase_name, ZEND_CALL_FUNC_NAME, sizeof(ZEND_CALL_FUNC_NAME))) {
1755 13565 : __call = reg_function;
1756 11679465 : } else if ((fname_len == sizeof(ZEND_TOSTRING_FUNC_NAME)-1) && !memcmp(lowercase_name, ZEND_TOSTRING_FUNC_NAME, sizeof(ZEND_TOSTRING_FUNC_NAME))) {
1757 189910 : __tostring = reg_function;
1758 11299645 : } else if ((fname_len == sizeof(ZEND_GET_FUNC_NAME)-1) && !memcmp(lowercase_name, ZEND_GET_FUNC_NAME, sizeof(ZEND_GET_FUNC_NAME))) {
1759 0 : __get = reg_function;
1760 11299645 : } else if ((fname_len == sizeof(ZEND_SET_FUNC_NAME)-1) && !memcmp(lowercase_name, ZEND_SET_FUNC_NAME, sizeof(ZEND_SET_FUNC_NAME))) {
1761 0 : __set = reg_function;
1762 11299645 : } else if ((fname_len == sizeof(ZEND_UNSET_FUNC_NAME)-1) && !memcmp(lowercase_name, ZEND_UNSET_FUNC_NAME, sizeof(ZEND_UNSET_FUNC_NAME))) {
1763 0 : __unset = reg_function;
1764 11299645 : } else if ((fname_len == sizeof(ZEND_ISSET_FUNC_NAME)-1) && !memcmp(lowercase_name, ZEND_ISSET_FUNC_NAME, sizeof(ZEND_ISSET_FUNC_NAME))) {
1765 0 : __isset = reg_function;
1766 : } else {
1767 11299645 : reg_function = NULL;
1768 : }
1769 12330585 : if (reg_function) {
1770 1030940 : zend_check_magic_method_implementation(scope, reg_function, error_type TSRMLS_CC);
1771 : }
1772 : }
1773 40396573 : ptr++;
1774 40396573 : count++;
1775 40396573 : efree(lowercase_name);
1776 : }
1777 2292489 : if (unload) { /* before unloading, display all remaining bad function in the module */
1778 0 : if (scope) {
1779 0 : efree(lc_class_name);
1780 : }
1781 0 : while (ptr->fname) {
1782 0 : fname_len = strlen(ptr->fname);
1783 0 : lowercase_name = zend_str_tolower_dup(ptr->fname, fname_len);
1784 0 : if (zend_hash_exists(target_function_table, lowercase_name, fname_len+1)) {
1785 0 : zend_error(error_type, "Function registration failed - duplicate name - %s%s%s", scope ? scope->name : "", scope ? "::" : "", ptr->fname);
1786 : }
1787 0 : efree(lowercase_name);
1788 0 : ptr++;
1789 : }
1790 0 : zend_unregister_functions(functions, count, target_function_table TSRMLS_CC);
1791 0 : return FAILURE;
1792 : }
1793 2292489 : if (scope) {
1794 1478586 : scope->constructor = ctor;
1795 1478586 : scope->destructor = dtor;
1796 1478586 : scope->clone = clone;
1797 1478586 : scope->__call = __call;
1798 1478586 : scope->__tostring = __tostring;
1799 1478586 : scope->__get = __get;
1800 1478586 : scope->__set = __set;
1801 1478586 : scope->__unset = __unset;
1802 1478586 : scope->__isset = __isset;
1803 1478586 : if (ctor) {
1804 746075 : ctor->common.fn_flags |= ZEND_ACC_CTOR;
1805 746075 : if (ctor->common.fn_flags & ZEND_ACC_STATIC) {
1806 0 : zend_error(error_type, "Constructor %s::%s() cannot be static", scope->name, ctor->common.function_name);
1807 : }
1808 746075 : ctor->common.fn_flags &= ~ZEND_ACC_ALLOW_STATIC;
1809 : }
1810 1478586 : if (dtor) {
1811 0 : dtor->common.fn_flags |= ZEND_ACC_DTOR;
1812 0 : if (dtor->common.fn_flags & ZEND_ACC_STATIC) {
1813 0 : zend_error(error_type, "Destructor %s::%s() cannot be static", scope->name, dtor->common.function_name);
1814 : }
1815 0 : dtor->common.fn_flags &= ~ZEND_ACC_ALLOW_STATIC;
1816 : }
1817 1478586 : if (clone) {
1818 81390 : clone->common.fn_flags |= ZEND_ACC_CLONE;
1819 81390 : if (clone->common.fn_flags & ZEND_ACC_STATIC) {
1820 0 : zend_error(error_type, "Constructor %s::%s() cannot be static", scope->name, clone->common.function_name);
1821 : }
1822 81390 : clone->common.fn_flags &= ~ZEND_ACC_ALLOW_STATIC;
1823 : }
1824 1478586 : if (__call) {
1825 13565 : if (__call->common.fn_flags & ZEND_ACC_STATIC) {
1826 0 : zend_error(error_type, "Method %s::%s() cannot be static", scope->name, __call->common.function_name);
1827 : }
1828 13565 : __call->common.fn_flags &= ~ZEND_ACC_ALLOW_STATIC;
1829 : }
1830 1478586 : if (__tostring) {
1831 189910 : if (__tostring->common.fn_flags & ZEND_ACC_STATIC) {
1832 0 : zend_error(error_type, "Method %s::%s() cannot be static", scope->name, __tostring->common.function_name);
1833 : }
1834 189910 : __tostring->common.fn_flags &= ~ZEND_ACC_ALLOW_STATIC;
1835 : }
1836 1478586 : if (__get) {
1837 0 : if (__get->common.fn_flags & ZEND_ACC_STATIC) {
1838 0 : zend_error(error_type, "Method %s::%s() cannot be static", scope->name, __get->common.function_name);
1839 : }
1840 0 : __get->common.fn_flags &= ~ZEND_ACC_ALLOW_STATIC;
1841 : }
1842 1478586 : if (__set) {
1843 0 : if (__set->common.fn_flags & ZEND_ACC_STATIC) {
1844 0 : zend_error(error_type, "Method %s::%s() cannot be static", scope->name, __set->common.function_name);
1845 : }
1846 0 : __set->common.fn_flags &= ~ZEND_ACC_ALLOW_STATIC;
1847 : }
1848 1478586 : if (__unset) {
1849 0 : if (__unset->common.fn_flags & ZEND_ACC_STATIC) {
1850 0 : zend_error(error_type, "Method %s::%s() cannot be static", scope->name, __unset->common.function_name);
1851 : }
1852 0 : __unset->common.fn_flags &= ~ZEND_ACC_ALLOW_STATIC;
1853 : }
1854 1478586 : if (__isset) {
1855 0 : if (__isset->common.fn_flags & ZEND_ACC_STATIC) {
1856 0 : zend_error(error_type, "Method %s::%s() cannot be static", scope->name, __isset->common.function_name);
1857 : }
1858 0 : __isset->common.fn_flags &= ~ZEND_ACC_ALLOW_STATIC;
1859 : }
1860 1478586 : efree(lc_class_name);
1861 : }
1862 2292489 : return SUCCESS;
1863 : }
1864 :
1865 : /* count=-1 means erase all functions, otherwise,
1866 : * erase the first count functions
1867 : */
1868 : ZEND_API void zend_unregister_functions(zend_function_entry *functions, int count, HashTable *function_table TSRMLS_DC)
1869 802253 : {
1870 802253 : zend_function_entry *ptr = functions;
1871 802253 : int i=0;
1872 802253 : HashTable *target_function_table = function_table;
1873 :
1874 802253 : if (!target_function_table) {
1875 802253 : target_function_table = CG(function_table);
1876 : }
1877 29125447 : while (ptr->fname) {
1878 27520941 : if (count!=-1 && i>=count) {
1879 0 : break;
1880 : }
1881 : #if 0
1882 : zend_printf("Unregistering %s()\n", ptr->fname);
1883 : #endif
1884 27520941 : zend_hash_del(target_function_table, ptr->fname, strlen(ptr->fname)+1);
1885 27520941 : ptr++;
1886 27520941 : i++;
1887 : }
1888 802253 : }
1889 :
1890 :
1891 : ZEND_API int zend_startup_module(zend_module_entry *module)
1892 0 : {
1893 : TSRMLS_FETCH();
1894 :
1895 0 : if ((module = zend_register_internal_module(module TSRMLS_CC)) != NULL &&
1896 : zend_startup_module_ex(module TSRMLS_CC) == SUCCESS) {
1897 0 : return SUCCESS;
1898 : }
1899 0 : return FAILURE;
1900 : }
1901 :
1902 :
1903 : ZEND_API int zend_get_module_started(char *module_name)
1904 13565 : {
1905 : zend_module_entry *module;
1906 :
1907 13565 : return (zend_hash_find(&module_registry, module_name, strlen(module_name)+1, (void**)&module) == SUCCESS && module->module_started) ? SUCCESS : FAILURE;
1908 : }
1909 :
1910 :
1911 : void module_destructor(zend_module_entry *module)
1912 815947 : {
1913 : TSRMLS_FETCH();
1914 :
1915 815947 : if (module->type == MODULE_TEMPORARY) {
1916 0 : zend_clean_module_rsrc_dtors(module->module_number TSRMLS_CC);
1917 0 : clean_module_constants(module->module_number TSRMLS_CC);
1918 : }
1919 :
1920 815947 : if (module->module_started && module->module_shutdown_func) {
1921 : #if 0
1922 : zend_printf("%s: Module shutdown\n", module->name);
1923 : #endif
1924 557590 : module->module_shutdown_func(module->type, module->module_number TSRMLS_CC);
1925 : }
1926 :
1927 : /* Deinitilaise module globals */
1928 815946 : if (module->globals_size) {
1929 : #ifdef ZTS
1930 : ts_free_id(*module->globals_id_ptr);
1931 : #else
1932 367132 : if (module->globals_dtor) {
1933 40791 : module->globals_dtor(module->globals_ptr TSRMLS_CC);
1934 : }
1935 : #endif
1936 : }
1937 :
1938 815946 : module->module_started=0;
1939 815946 : if (module->functions) {
1940 802253 : zend_unregister_functions(module->functions, -1, NULL TSRMLS_CC);
1941 : }
1942 :
1943 : #if HAVE_LIBDL || defined(HAVE_MACH_O_DYLD_H)
1944 : #if !(defined(NETWARE) && defined(APACHE_1_BUILD))
1945 815946 : if (module->handle) {
1946 0 : DL_UNLOAD(module->handle);
1947 : }
1948 : #endif
1949 : #endif
1950 815946 : }
1951 :
1952 :
1953 : /* call request startup for all modules */
1954 : int module_registry_request_startup(zend_module_entry *module TSRMLS_DC)
1955 813158 : {
1956 813158 : if (module->request_startup_func) {
1957 : #if 0
1958 : zend_printf("%s: Request startup\n", module->name);
1959 : #endif
1960 230367 : if (module->request_startup_func(module->type, module->module_number TSRMLS_CC)==FAILURE) {
1961 0 : zend_error(E_WARNING, "request_startup() for %s module failed", module->name);
1962 0 : exit(1);
1963 : }
1964 : }
1965 813158 : return 0;
1966 : }
1967 :
1968 :
1969 : /* call request shutdown for all modules */
1970 : int module_registry_cleanup(zend_module_entry *module TSRMLS_DC)
1971 815135 : {
1972 815135 : if (module->request_shutdown_func) {
1973 : #if 0
1974 : zend_printf("%s: Request shutdown\n", module->name);
1975 : #endif
1976 258096 : module->request_shutdown_func(module->type, module->module_number TSRMLS_CC);
1977 : }
1978 815135 : return 0;
1979 : }
1980 :
1981 : int module_registry_unload_temp(zend_module_entry *module TSRMLS_DC)
1982 13584 : {
1983 13584 : return (module->type == MODULE_TEMPORARY) ? ZEND_HASH_APPLY_REMOVE : ZEND_HASH_APPLY_STOP;
1984 : }
1985 :
1986 :
1987 : /* return the next free module number */
1988 : int zend_next_free_module(void)
1989 813998 : {
1990 813998 : return ++module_count;
1991 : }
1992 :
1993 : static zend_class_entry *do_register_internal_class(zend_class_entry *orig_class_entry, zend_uint ce_flags TSRMLS_DC)
1994 1722756 : {
1995 1722756 : zend_class_entry *class_entry = malloc(sizeof(zend_class_entry));
1996 1722756 : char *lowercase_name = malloc(orig_class_entry->name_length + 1);
1997 1722756 : *class_entry = *orig_class_entry;
1998 :
1999 1722756 : class_entry->type = ZEND_INTERNAL_CLASS;
2000 1722756 : zend_initialize_class_data(class_entry, 0 TSRMLS_CC);
2001 1722756 : class_entry->ce_flags = ce_flags;
2002 1722756 : class_entry->module = EG(current_module);
2003 :
2004 1722756 : if (class_entry->builtin_functions) {
2005 1478586 : zend_register_functions(class_entry, class_entry->builtin_functions, &class_entry->function_table, MODULE_PERSISTENT TSRMLS_CC);
2006 : }
2007 :
2008 1722756 : zend_str_tolower_copy(lowercase_name, orig_class_entry->name, class_entry->name_length);
2009 1722756 : zend_hash_update(CG(class_table), lowercase_name, class_entry->name_length+1, &class_entry, sizeof(zend_class_entry *), NULL);
2010 1722756 : free(lowercase_name);
2011 1722756 : return class_entry;
2012 : }
2013 :
2014 : /* If parent_ce is not NULL then it inherits from parent_ce
2015 : * If parent_ce is NULL and parent_name isn't then it looks for the parent and inherits from it
2016 : * If both parent_ce and parent_name are NULL it does a regular class registration
2017 : * If parent_name is specified but not found NULL is returned
2018 : */
2019 : ZEND_API zend_class_entry *zend_register_internal_class_ex(zend_class_entry *class_entry, zend_class_entry *parent_ce, char *parent_name TSRMLS_DC)
2020 1058070 : {
2021 : zend_class_entry *register_class;
2022 :
2023 1058070 : if (!parent_ce && parent_name) {
2024 : zend_class_entry **pce;
2025 0 : if (zend_hash_find(CG(class_table), parent_name, strlen(parent_name)+1, (void **) &pce)==FAILURE) {
2026 0 : return NULL;
2027 : } else {
2028 0 : parent_ce = *pce;
2029 : }
2030 : }
2031 :
2032 1058070 : register_class = zend_register_internal_class(class_entry TSRMLS_CC);
2033 :
2034 1058070 : if (parent_ce) {
2035 705380 : zend_do_inheritance(register_class, parent_ce TSRMLS_CC);
2036 : }
2037 1058070 : return register_class;
2038 : }
2039 :
2040 : ZEND_API void zend_class_implements(zend_class_entry *class_entry TSRMLS_DC, int num_interfaces, ...)
2041 474775 : {
2042 : zend_class_entry *interface_entry;
2043 : va_list interface_list;
2044 474775 : va_start(interface_list, num_interfaces);
2045 :
2046 1437890 : while (num_interfaces--) {
2047 488340 : interface_entry = va_arg(interface_list, zend_class_entry *);
2048 488340 : zend_do_implement_interface(class_entry, interface_entry TSRMLS_CC);
2049 : }
2050 :
2051 474775 : va_end(interface_list);
2052 474775 : }
2053 :
2054 : /* A class that contains at least one abstract method automatically becomes an abstract class.
2055 : */
2056 : ZEND_API zend_class_entry *zend_register_internal_class(zend_class_entry *orig_class_entry TSRMLS_DC)
2057 1559976 : {
2058 1559976 : return do_register_internal_class(orig_class_entry, 0 TSRMLS_CC);
2059 : }
2060 :
2061 : ZEND_API zend_class_entry *zend_register_internal_interface(zend_class_entry *orig_class_entry TSRMLS_DC)
2062 162780 : {
2063 162780 : return do_register_internal_class(orig_class_entry, ZEND_ACC_INTERFACE TSRMLS_CC);
2064 : }
2065 :
2066 : ZEND_API int zend_set_hash_symbol(zval *symbol, char *name, int name_length,
2067 : zend_bool is_ref, int num_symbol_tables, ...)
2068 139 : {
2069 : HashTable *symbol_table;
2070 : va_list symbol_table_list;
2071 :
2072 139 : if (num_symbol_tables <= 0) return FAILURE;
2073 :
2074 139 : symbol->is_ref = is_ref;
2075 :
2076 139 : va_start(symbol_table_list, num_symbol_tables);
2077 432 : while (num_symbol_tables-- > 0) {
2078 154 : symbol_table = va_arg(symbol_table_list, HashTable *);
2079 154 : zend_hash_update(symbol_table, name, name_length + 1, &symbol, sizeof(zval *), NULL);
2080 154 : zval_add_ref(&symbol);
2081 : }
2082 139 : va_end(symbol_table_list);
2083 139 : return SUCCESS;
2084 : }
2085 :
2086 :
2087 :
2088 :
2089 : /* Disabled functions support */
2090 :
2091 : ZEND_API ZEND_FUNCTION(display_disabled_function)
2092 1 : {
2093 1 : zend_error(E_WARNING, "%s() has been disabled for security reasons", get_active_function_name(TSRMLS_C));
2094 1 : }
2095 :
2096 :
2097 : static zend_function_entry disabled_function[] = {
2098 : ZEND_FE(display_disabled_function, NULL)
2099 : { NULL, NULL, NULL }
2100 : };
2101 :
2102 :
2103 : ZEND_API int zend_disable_function(char *function_name, uint function_name_length TSRMLS_DC)
2104 3 : {
2105 3 : if (zend_hash_del(CG(function_table), function_name, function_name_length+1)==FAILURE) {
2106 0 : return FAILURE;
2107 : }
2108 3 : disabled_function[0].fname = function_name;
2109 3 : return zend_register_functions(NULL, disabled_function, CG(function_table), MODULE_PERSISTENT TSRMLS_CC);
2110 : }
2111 :
2112 : static zend_object_value display_disabled_class(zend_class_entry *class_type TSRMLS_DC)
2113 1 : {
2114 : zend_object_value retval;
2115 : zend_object *intern;
2116 1 : retval = zend_objects_new(&intern, class_type TSRMLS_CC);
2117 1 : ALLOC_HASHTABLE(intern->properties);
2118 1 : zend_hash_init(intern->properties, 0, NULL, ZVAL_PTR_DTOR, 0);
2119 1 : zend_error(E_WARNING, "%s() has been disabled for security reasons", class_type->name);
2120 1 : return retval;
2121 : }
2122 :
2123 : static zend_function_entry disabled_class_new[] = {
2124 : { NULL, NULL, NULL }
2125 : };
2126 :
2127 : ZEND_API int zend_disable_class(char *class_name, uint class_name_length TSRMLS_DC)
2128 1 : {
2129 : zend_class_entry disabled_class;
2130 :
2131 1 : zend_str_tolower(class_name, class_name_length);
2132 1 : if (zend_hash_del(CG(class_table), class_name, class_name_length+1)==FAILURE) {
2133 0 : return FAILURE;
2134 : }
2135 1 : INIT_CLASS_ENTRY(disabled_class, class_name, disabled_class_new);
2136 1 : disabled_class.create_object = display_disabled_class;
2137 1 : disabled_class.name_length = class_name_length;
2138 1 : zend_register_internal_class(&disabled_class TSRMLS_CC);
2139 1 : return SUCCESS;
2140 : }
2141 :
2142 : static int zend_is_callable_check_func(int check_flags, zval ***zobj_ptr_ptr, zend_class_entry *ce_org, zval *callable, zend_class_entry **ce_ptr, zend_function **fptr_ptr TSRMLS_DC)
2143 3504 : {
2144 : int retval;
2145 : char *lcname, *lmname, *colon;
2146 : int clen, mlen;
2147 : zend_function *fptr;
2148 : zend_class_entry **pce;
2149 : HashTable *ftable;
2150 :
2151 3504 : *ce_ptr = NULL;
2152 3504 : *fptr_ptr = NULL;
2153 :
2154 3504 : if ((colon = strstr(Z_STRVAL_P(callable), "::")) != NULL) {
2155 31 : clen = colon - Z_STRVAL_P(callable);
2156 31 : mlen = Z_STRLEN_P(callable) - clen - 2;
2157 31 : lcname = zend_str_tolower_dup(Z_STRVAL_P(callable), clen);
2158 : /* caution: lcname is not '\0' terminated */
2159 31 : if (clen == sizeof("self") - 1 && memcmp(lcname, "self", sizeof("self") - 1) == 0) {
2160 0 : *ce_ptr = EG(scope);
2161 35 : } else if (clen == sizeof("parent") - 1 && memcmp(lcname, "parent", sizeof("parent") - 1) == 0 && EG(active_op_array)->scope) {
2162 4 : *ce_ptr = EG(scope) ? EG(scope)->parent : NULL;
2163 27 : } else if (zend_lookup_class(Z_STRVAL_P(callable), clen, &pce TSRMLS_CC) == SUCCESS) {
2164 25 : *ce_ptr = *pce;
2165 : }
2166 30 : efree(lcname);
2167 30 : if (!*ce_ptr) {
2168 1 : return 0;
2169 : }
2170 29 : ftable = &(*ce_ptr)->function_table;
2171 29 : if (ce_org && !instanceof_function(ce_org, *ce_ptr TSRMLS_CC)) {
2172 0 : return 0;
2173 : }
2174 29 : lmname = zend_str_tolower_dup(Z_STRVAL_P(callable) + clen + 2, mlen);
2175 : } else {
2176 3473 : mlen = Z_STRLEN_P(callable);
2177 3473 : lmname = zend_str_tolower_dup(Z_STRVAL_P(callable), mlen);
2178 3473 : if (ce_org) {
2179 428 : ftable = &ce_org->function_table;
2180 428 : *ce_ptr = ce_org;
2181 : } else {
2182 3045 : ftable = EG(function_table);
2183 : }
2184 : }
2185 :
2186 3502 : retval = zend_hash_find(ftable, lmname, mlen+1, (void**)&fptr) == SUCCESS ? 1 : 0;
2187 :
2188 3502 : if (!retval) {
2189 347 : if (*zobj_ptr_ptr && *ce_ptr && (*ce_ptr)->__call != 0) {
2190 7 : retval = (*ce_ptr)->__call != NULL;
2191 7 : *fptr_ptr = (*ce_ptr)->__call;
2192 : }
2193 : } else {
2194 3155 : *fptr_ptr = fptr;
2195 3155 : if (*ce_ptr) {
2196 328 : if (!*zobj_ptr_ptr && !(fptr->common.fn_flags & ZEND_ACC_STATIC)) {
2197 45 : if ((check_flags & IS_CALLABLE_CHECK_IS_STATIC) != 0) {
2198 8 : retval = 0;
2199 : } else {
2200 41 : if (EG(This) && instanceof_function(Z_OBJCE_P(EG(This)), *ce_ptr TSRMLS_CC)) {
2201 4 : *zobj_ptr_ptr = &EG(This);
2202 4 : zend_error(E_STRICT, "Non-static method %s::%s() cannot be called statically, assuming $this from compatible context %s", (*ce_ptr)->name, fptr->common.function_name, Z_OBJCE_P(EG(This))->name);
2203 : } else {
2204 33 : zend_error(E_STRICT, "Non-static method %s::%s() cannot be called statically", (*ce_ptr)->name, fptr->common.function_name);
2205 : }
2206 : }
2207 : }
2208 328 : if (retval && (check_flags & IS_CALLABLE_CHECK_NO_ACCESS) == 0) {
2209 317 : if (fptr->op_array.fn_flags & ZEND_ACC_PRIVATE) {
2210 21 : if (!zend_check_private(fptr, *zobj_ptr_ptr ? Z_OBJCE_PP(*zobj_ptr_ptr) : EG(scope), lmname, mlen TSRMLS_CC)) {
2211 17 : retval = 0;
2212 : }
2213 296 : } else if ((fptr->common.fn_flags & ZEND_ACC_PROTECTED)) {
2214 23 : if (!zend_check_protected(fptr->common.scope, EG(scope))) {
2215 17 : retval = 0;
2216 : }
2217 : }
2218 317 : if (!retval && *zobj_ptr_ptr && *ce_ptr && (*ce_ptr)->__call != 0) {
2219 2 : retval = (*ce_ptr)->__call != NULL;
2220 2 : *fptr_ptr = (*ce_ptr)->__call;
2221 : }
2222 : }
2223 : }
2224 : }
2225 3502 : efree(lmname);
2226 3502 : return retval;
2227 : }
2228 :
2229 : ZEND_API zend_bool zend_is_callable_ex(zval *callable, uint check_flags, char **callable_name, int *callable_name_len, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zval ***zobj_ptr_ptr TSRMLS_DC)
2230 4343 : {
2231 : char *lcname;
2232 4343 : zend_bool retval = 0;
2233 : int callable_name_len_local;
2234 : zend_class_entry *ce_local, **pce;
2235 : zend_function *fptr_local;
2236 : zval **zobj_ptr_local;
2237 :
2238 4343 : if (callable_name) {
2239 3692 : *callable_name = NULL;
2240 : }
2241 4343 : if (callable_name_len == NULL) {
2242 4290 : callable_name_len = &callable_name_len_local;
2243 : }
2244 4343 : if (ce_ptr == NULL) {
2245 4270 : ce_ptr = &ce_local;
2246 : }
2247 4343 : if (fptr_ptr == NULL) {
2248 4270 : fptr_ptr = &fptr_local;
2249 : }
2250 4343 : if (zobj_ptr_ptr == NULL) {
2251 4259 : zobj_ptr_ptr = &zobj_ptr_local;
2252 : }
2253 4343 : *ce_ptr = NULL;
2254 4343 : *fptr_ptr = NULL;
2255 4343 : *zobj_ptr_ptr = NULL;
2256 :
2257 4343 : switch (Z_TYPE_P(callable)) {
2258 : case IS_STRING:
2259 3124 : if (callable_name) {
2260 2840 : *callable_name = estrndup(Z_STRVAL_P(callable), Z_STRLEN_P(callable));
2261 2840 : *callable_name_len = Z_STRLEN_P(callable);
2262 : }
2263 3124 : if (check_flags & IS_CALLABLE_CHECK_SYNTAX_ONLY) {
2264 54 : return 1;
2265 : }
2266 :
2267 3070 : retval = zend_is_callable_check_func(check_flags|IS_CALLABLE_CHECK_IS_STATIC, zobj_ptr_ptr, NULL, callable, ce_ptr, fptr_ptr TSRMLS_CC);
2268 3069 : break;
2269 :
2270 : case IS_ARRAY:
2271 : {
2272 764 : zend_class_entry *ce = NULL;
2273 : zval **method;
2274 : zval **obj;
2275 :
2276 1205 : if (zend_hash_num_elements(Z_ARRVAL_P(callable)) == 2 &&
2277 : zend_hash_index_find(Z_ARRVAL_P(callable), 0, (void **) &obj) == SUCCESS &&
2278 : zend_hash_index_find(Z_ARRVAL_P(callable), 1, (void **) &method) == SUCCESS &&
2279 : (Z_TYPE_PP(obj) == IS_OBJECT || Z_TYPE_PP(obj) == IS_STRING) &&
2280 : Z_TYPE_PP(method) == IS_STRING) {
2281 :
2282 573 : if (Z_TYPE_PP(obj) == IS_STRING) {
2283 131 : if (callable_name) {
2284 : char *ptr;
2285 :
2286 96 : *callable_name_len = Z_STRLEN_PP(obj) + Z_STRLEN_PP(method) + sizeof("::") - 1;
2287 96 : ptr = *callable_name = emalloc(*callable_name_len + 1);
2288 96 : memcpy(ptr, Z_STRVAL_PP(obj), Z_STRLEN_PP(obj));
2289 96 : ptr += Z_STRLEN_PP(obj);
2290 96 : memcpy(ptr, "::", sizeof("::") - 1);
2291 96 : ptr += sizeof("::") - 1;
2292 96 : memcpy(ptr, Z_STRVAL_PP(method), Z_STRLEN_PP(method) + 1);
2293 : }
2294 :
2295 131 : if (check_flags & IS_CALLABLE_CHECK_SYNTAX_ONLY) {
2296 18 : return 1;
2297 : }
2298 :
2299 113 : lcname = zend_str_tolower_dup(Z_STRVAL_PP(obj), Z_STRLEN_PP(obj));
2300 115 : if (Z_STRLEN_PP(obj) == sizeof("self") - 1 && memcmp(lcname, "self", sizeof("self")) == 0 && EG(active_op_array)) {
2301 2 : ce = EG(active_op_array)->scope;
2302 114 : } else if (Z_STRLEN_PP(obj) == sizeof("parent") - 1 && memcmp(lcname, "parent", sizeof("parent")) == 0 && EG(active_op_array) && EG(active_op_array)->scope) {
2303 3 : ce = EG(active_op_array)->scope->parent;
2304 108 : } else if (zend_lookup_class(Z_STRVAL_PP(obj), Z_STRLEN_PP(obj), &pce TSRMLS_CC) == SUCCESS) {
2305 101 : ce = *pce;
2306 : }
2307 113 : efree(lcname);
2308 : } else {
2309 442 : ce = Z_OBJCE_PP(obj); /* TBFixed: what if it's overloaded? */
2310 :
2311 442 : *zobj_ptr_ptr = obj;
2312 :
2313 442 : if (callable_name) {
2314 : char *ptr;
2315 :
2316 262 : *callable_name_len = ce->name_length + Z_STRLEN_PP(method) + sizeof("::") - 1;
2317 262 : ptr = *callable_name = emalloc(*callable_name_len + 1);
2318 262 : memcpy(ptr, ce->name, ce->name_length);
2319 262 : ptr += ce->name_length;
2320 262 : memcpy(ptr, "::", sizeof("::") - 1);
2321 262 : ptr += sizeof("::") - 1;
2322 262 : memcpy(ptr, Z_STRVAL_PP(method), Z_STRLEN_PP(method) + 1);
2323 : }
2324 :
2325 442 : if (check_flags & IS_CALLABLE_CHECK_SYNTAX_ONLY) {
2326 114 : *ce_ptr = ce;
2327 114 : return 1;
2328 : }
2329 : }
2330 :
2331 441 : if (ce) {
2332 434 : retval = zend_is_callable_check_func(check_flags, zobj_ptr_ptr, ce, *method, ce_ptr, fptr_ptr TSRMLS_CC);
2333 : }
2334 191 : } else if (callable_name) {
2335 126 : *callable_name = estrndup("Array", sizeof("Array")-1);
2336 126 : *callable_name_len = sizeof("Array") - 1;
2337 : }
2338 632 : *ce_ptr = ce;
2339 : }
2340 632 : break;
2341 :
2342 : default:
2343 455 : if (callable_name) {
2344 : zval expr_copy;
2345 : int use_copy;
2346 :
2347 368 : zend_make_printable_zval(callable, &expr_copy, &use_copy);
2348 368 : *callable_name = estrndup(Z_STRVAL(expr_copy), Z_STRLEN(expr_copy));
2349 368 : *callable_name_len = Z_STRLEN(expr_copy);
2350 368 : zval_dtor(&expr_copy);
2351 : }
2352 : break;
2353 : }
2354 :
2355 4156 : return retval;
2356 : }
2357 :
2358 :
2359 : ZEND_API zend_bool zend_is_callable(zval *callable, uint check_flags, char **callable_name)
2360 4259 : {
2361 : TSRMLS_FETCH();
2362 :
2363 4259 : return zend_is_callable_ex(callable, check_flags, callable_name, NULL, NULL, NULL, NULL TSRMLS_CC);
2364 : }
2365 :
2366 :
2367 : ZEND_API zend_bool zend_make_callable(zval *callable, char **callable_name TSRMLS_DC)
2368 23 : {
2369 : zend_class_entry *ce;
2370 : zend_function *fptr;
2371 : zval **zobj_ptr;
2372 :
2373 23 : if (zend_is_callable_ex(callable, 0, callable_name, NULL, &ce, &fptr, &zobj_ptr TSRMLS_CC)) {
2374 20 : if (Z_TYPE_P(callable) == IS_STRING && ce) {
2375 4 : zval_dtor(callable);
2376 4 : array_init(callable);
2377 4 : add_next_index_string(callable, ce->name, 1);
2378 4 : add_next_index_string(callable, fptr->common.function_name, 1);
2379 : }
2380 20 : return 1;
2381 : }
2382 2 : return 0;
2383 : }
2384 :
2385 :
2386 : ZEND_API int zend_fcall_info_init(zval *callable, zend_fcall_info *fci, zend_fcall_info_cache *fcc TSRMLS_DC)
2387 8 : {
2388 : zend_class_entry *ce;
2389 : zend_function *func;
2390 : zval **obj;
2391 :
2392 8 : if (!zend_is_callable_ex(callable, IS_CALLABLE_STRICT, NULL, NULL, &ce, &func, &obj TSRMLS_CC)) {
2393 1 : return FAILURE;
2394 : }
2395 :
2396 7 : fci->size = sizeof(*fci);
2397 7 : fci->function_table = ce ? &ce->function_table : EG(function_table);
2398 7 : fci->object_pp = obj;
2399 7 : fci->function_name = callable;
2400 7 : fci->retval_ptr_ptr = NULL;
2401 7 : fci->param_count = 0;
2402 7 : fci->params = NULL;
2403 7 : fci->no_separation = 1;
2404 7 : fci->symbol_table = NULL;
2405 :
2406 8 : if (strlen(func->common.function_name) == sizeof(ZEND_CALL_FUNC_NAME) - 1 && !memcmp(func->common.function_name, ZEND_CALL_FUNC_NAME, sizeof(ZEND_CALL_FUNC_NAME))) {
2407 1 : fcc->initialized = 0;
2408 1 : fcc->function_handler = NULL;
2409 1 : fcc->calling_scope = NULL;
2410 1 : fcc->object_pp = NULL;
2411 : } else {
2412 6 : fcc->initialized = 1;
2413 6 : fcc->function_handler = func;
2414 6 : fcc->calling_scope = ce;
2415 6 : fcc->object_pp = obj;
2416 : }
2417 :
2418 7 : return SUCCESS;
2419 : }
2420 :
2421 :
2422 : ZEND_API void zend_fcall_info_args_clear(zend_fcall_info *fci, int free_mem)
2423 12 : {
2424 12 : if (fci->params) {
2425 3 : while (fci->param_count) {
2426 1 : zval_ptr_dtor(fci->params[--fci->param_count]);
2427 : }
2428 1 : if (free_mem) {
2429 1 : efree(fci->params);
2430 1 : fci->params = NULL;
2431 : }
2432 : }
2433 12 : fci->param_count = 0;
2434 12 : }
2435 :
2436 : ZEND_API void zend_fcall_info_args_save(zend_fcall_info *fci, int *param_count, zval ****params)
2437 0 : {
2438 0 : *param_count = fci->param_count;
2439 0 : *params = fci->params;
2440 0 : fci->param_count = 0;
2441 0 : fci->params = NULL;
2442 0 : }
2443 :
2444 : ZEND_API void zend_fcall_info_args_restore(zend_fcall_info *fci, int param_count, zval ***params)
2445 0 : {
2446 0 : zend_fcall_info_args_clear(fci, 1);
2447 0 : fci->param_count = param_count;
2448 0 : fci->params = params;
2449 0 : }
2450 :
2451 : ZEND_API int zend_fcall_info_args(zend_fcall_info *fci, zval *args TSRMLS_DC)
2452 12 : {
2453 : HashPosition pos;
2454 : zval **arg, ***params;
2455 :
2456 12 : zend_fcall_info_args_clear(fci, !args);
2457 :
2458 12 : if (!args) {
2459 11 : return SUCCESS;
2460 : }
2461 :
2462 1 : if (Z_TYPE_P(args) != IS_ARRAY) {
2463 0 : return FAILURE;
2464 : }
2465 :
2466 1 : fci->param_count = zend_hash_num_elements(Z_ARRVAL_P(args));
2467 1 : fci->params = params = (zval***)safe_emalloc(sizeof(zval**), fci->param_count, 0);
2468 :
2469 1 : zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(args), &pos);
2470 3 : while (zend_hash_get_current_data_ex(Z_ARRVAL_P(args), (void **) &arg, &pos) == SUCCESS) {
2471 1 : *params++ = arg;
2472 1 : (*arg)->refcount++;
2473 1 : zend_hash_move_forward_ex(Z_ARRVAL_P(args), &pos);
2474 : }
2475 1 : return SUCCESS;
2476 : }
2477 :
2478 :
2479 : ZEND_API int zend_fcall_info_call(zend_fcall_info *fci, zend_fcall_info_cache *fcc, zval **retval_ptr_ptr, zval *args TSRMLS_DC)
2480 14 : {
2481 14 : zval *retval, ***org_params = NULL;
2482 14 : int result, org_count = 0;
2483 :
2484 14 : fci->retval_ptr_ptr = retval_ptr_ptr ? retval_ptr_ptr : &retval;
2485 14 : if (args) {
2486 0 : zend_fcall_info_args_save(fci, &org_count, &org_params);
2487 0 : zend_fcall_info_args(fci, args TSRMLS_CC);
2488 : }
2489 14 : result = zend_call_function(fci, fcc TSRMLS_CC);
2490 :
2491 14 : if (!retval_ptr_ptr && retval) {
2492 0 : zval_ptr_dtor(&retval);
2493 : }
2494 14 : if (args) {
2495 0 : zend_fcall_info_args_restore(fci, org_count, org_params);
2496 : }
2497 14 : return result;
2498 : }
2499 :
2500 :
2501 : ZEND_API char *zend_get_module_version(char *module_name)
2502 0 : {
2503 : char *lname;
2504 0 : int name_len = strlen(module_name);
2505 : zend_module_entry *module;
2506 :
2507 0 : lname = zend_str_tolower_dup(module_name, name_len);
2508 0 : if (zend_hash_find(&module_registry, lname, name_len + 1,
2509 : (void**)&module) == FAILURE) {
2510 0 : efree(lname);
2511 0 : return NULL;
2512 : }
2513 0 : efree(lname);
2514 0 : return module->version;
2515 : }
2516 :
2517 :
2518 : ZEND_API int zend_declare_property(zend_class_entry *ce, char *name, int name_length, zval *property, int access_type TSRMLS_DC)
2519 325560 : {
2520 325560 : return zend_declare_property_ex(ce, name, name_length, property, access_type, NULL, 0 TSRMLS_CC);
2521 : }
2522 :
2523 : ZEND_API int zend_declare_property_ex(zend_class_entry *ce, char *name, int name_length, zval *property, int access_type, char *doc_comment, int doc_comment_len TSRMLS_DC)
2524 327189 : {
2525 : zend_property_info property_info;
2526 : HashTable *target_symbol_table;
2527 :
2528 327189 : if (!(access_type & ZEND_ACC_PPP_MASK)) {
2529 27146 : access_type |= ZEND_ACC_PUBLIC;
2530 : }
2531 327189 : if (access_type & ZEND_ACC_STATIC) {
2532 230 : target_symbol_table = &ce->default_static_members;
2533 : } else {
2534 326959 : target_symbol_table = &ce->default_properties;
2535 : }
2536 327189 : if (ce->type & ZEND_INTERNAL_CLASS) {
2537 325560 : switch(Z_TYPE_P(property)) {
2538 : case IS_ARRAY:
2539 : case IS_CONSTANT_ARRAY:
2540 : case IS_OBJECT:
2541 : case IS_RESOURCE:
2542 0 : zend_error(E_CORE_ERROR, "Internal zval's can't be arrays, objects or resources");
2543 : break;
2544 : default:
2545 : break;
2546 : }
2547 : }
2548 327189 : switch (access_type & ZEND_ACC_PPP_MASK) {
2549 : case ZEND_ACC_PRIVATE: {
2550 : char *priv_name;
2551 : int priv_name_length;
2552 :
2553 27525 : zend_mangle_property_name(&priv_name, &priv_name_length, ce->name, ce->name_length, name, name_length, ce->type & ZEND_INTERNAL_CLASS);
2554 27525 : zend_hash_update(target_symbol_table, priv_name, priv_name_length+1, &property, sizeof(zval *), NULL);
2555 27525 : property_info.name = priv_name;
2556 27525 : property_info.name_length = priv_name_length;
2557 : }
2558 27525 : break;
2559 : case ZEND_ACC_PROTECTED: {
2560 : char *prot_name;
2561 : int prot_name_length;
2562 :
2563 95218 : zend_mangle_property_name(&prot_name, &prot_name_length, "*", 1, name, name_length, ce->type & ZEND_INTERNAL_CLASS);
2564 95218 : zend_hash_update(target_symbol_table, prot_name, prot_name_length+1, &property, sizeof(zval *), NULL);
2565 95218 : property_info.name = prot_name;
2566 95218 : property_info.name_length = prot_name_length;
2567 : }
2568 95218 : break;
2569 : case ZEND_ACC_PUBLIC:
2570 204446 : if (ce->parent) {
2571 : char *prot_name;
2572 : int prot_name_length;
2573 :
2574 81390 : zend_mangle_property_name(&prot_name, &prot_name_length, "*", 1, name, name_length, ce->type & ZEND_INTERNAL_CLASS);
2575 81390 : zend_hash_del(target_symbol_table, prot_name, prot_name_length+1);
2576 81390 : pefree(prot_name, ce->type & ZEND_INTERNAL_CLASS);
2577 : }
2578 204446 : zend_hash_update(target_symbol_table, name, name_length+1, &property, sizeof(zval *), NULL);
2579 204446 : property_info.name = ce->type & ZEND_INTERNAL_CLASS ? zend_strndup(name, name_length) : estrndup(name, name_length);
2580 204446 : property_info.name_length = name_length;
2581 : break;
2582 : }
2583 327189 : property_info.flags = access_type;
2584 327189 : property_info.h = zend_get_hash_value(property_info.name, property_info.name_length+1);
2585 :
2586 327189 : property_info.doc_comment = doc_comment;
2587 327189 : property_info.doc_comment_len = doc_comment_len;
2588 :
2589 327189 : property_info.ce = ce;
2590 :
2591 327189 : zend_hash_update(&ce->properties_info, name, name_length + 1, &property_info, sizeof(zend_property_info), NULL);
2592 :
2593 327189 : return SUCCESS;
2594 : }
2595 :
2596 : ZEND_API int zend_declare_property_null(zend_class_entry *ce, char *name, int name_length, int access_type TSRMLS_DC)
2597 81390 : {
2598 : zval *property;
2599 :
2600 81390 : if (ce->type & ZEND_INTERNAL_CLASS) {
2601 81390 : property = malloc(sizeof(zval));
2602 : } else {
2603 0 : ALLOC_ZVAL(property);
2604 : }
2605 81390 : INIT_ZVAL(*property);
2606 81390 : return zend_declare_property(ce, name, name_length, property, access_type TSRMLS_CC);
2607 : }
2608 :
2609 : ZEND_API int zend_declare_property_bool(zend_class_entry *ce, char *name, int name_length, long value, int access_type TSRMLS_DC)
2610 0 : {
2611 : zval *property;
2612 :
2613 0 : if (ce->type & ZEND_INTERNAL_CLASS) {
2614 0 : property = malloc(sizeof(zval));
2615 : } else {
2616 0 : ALLOC_ZVAL(property);
2617 : }
2618 0 : INIT_PZVAL(property);
2619 0 : ZVAL_BOOL(property, value);
2620 0 : return zend_declare_property(ce, name, name_length, property, access_type TSRMLS_CC);
2621 : }
2622 :
2623 : ZEND_API int zend_declare_property_long(zend_class_entry *ce, char *name, int name_length, long value, int access_type TSRMLS_DC)
2624 54260 : {
2625 : zval *property;
2626 :
2627 54260 : if (ce->type & ZEND_INTERNAL_CLASS) {
2628 54260 : property = malloc(sizeof(zval));
2629 : } else {
2630 0 : ALLOC_ZVAL(property);
2631 : }
2632 54260 : INIT_PZVAL(property);
2633 54260 : ZVAL_LONG(property, value);
2634 54260 : return zend_declare_property(ce, name, name_length, property, access_type TSRMLS_CC);
2635 : }
2636 :
2637 : ZEND_API int zend_declare_property_double(zend_class_entry *ce, char *name, int name_length, double value, int access_type TSRMLS_DC)
2638 0 : {
2639 : zval *property;
2640 :
2641 0 : if (ce->type & ZEND_INTERNAL_CLASS) {
2642 0 : property = malloc(sizeof(zval));
2643 : } else {
2644 0 : ALLOC_ZVAL(property);
2645 : }
2646 0 : INIT_PZVAL(property);
2647 0 : ZVAL_DOUBLE(property, value);
2648 0 : return zend_declare_property(ce, name, name_length, property, access_type TSRMLS_CC);
2649 : }
2650 :
2651 : ZEND_API int zend_declare_property_string(zend_class_entry *ce, char *name, int name_length, char *value, int access_type TSRMLS_DC)
2652 189910 : {
2653 : zval *property;
2654 189910 : int len = strlen(value);
2655 :
2656 189910 : if (ce->type & ZEND_INTERNAL_CLASS) {
2657 189910 : property = malloc(sizeof(zval));
2658 189910 : ZVAL_STRINGL(property, zend_strndup(value, len), len, 0);
2659 : } else {
2660 0 : ALLOC_ZVAL(property);
2661 0 : ZVAL_STRINGL(property, value, len, 1);
2662 : }
2663 189910 : INIT_PZVAL(property);
2664 189910 : return zend_declare_property(ce, name, name_length, property, access_type TSRMLS_CC);
2665 : }
2666 :
2667 : ZEND_API int zend_declare_property_stringl(zend_class_entry *ce, char *name, int name_length, char *value, int value_len, int access_type TSRMLS_DC)
2668 0 : {
2669 : zval *property;
2670 :
2671 0 : if (ce->type & ZEND_INTERNAL_CLASS) {
2672 0 : property = malloc(sizeof(zval));
2673 0 : ZVAL_STRINGL(property, zend_strndup(value, value_len), value_len, 0);
2674 : } else {
2675 0 : ALLOC_ZVAL(property);
2676 0 : ZVAL_STRINGL(property, value, value_len, 1);
2677 : }
2678 0 : INIT_PZVAL(property);
2679 0 : return zend_declare_property(ce, name, name_length, property, access_type TSRMLS_CC);
2680 : }
2681 :
2682 : ZEND_API int zend_declare_class_constant(zend_class_entry *ce, char *name, size_t name_length, zval *value TSRMLS_DC)
2683 2726565 : {
2684 2726565 : return zend_hash_update(&ce->constants_table, name, name_length+1, &value, sizeof(zval *), NULL);
2685 : }
2686 :
2687 : ZEND_API int zend_declare_class_constant_null(zend_class_entry *ce, char *name, size_t name_length TSRMLS_DC)
2688 0 : {
2689 : zval *constant;
2690 :
2691 0 : if (ce->type & ZEND_INTERNAL_CLASS) {
2692 0 : constant = malloc(sizeof(zval));
2693 : } else {
2694 0 : ALLOC_ZVAL(constant);
2695 : }
2696 0 : ZVAL_NULL(constant);
2697 0 : INIT_PZVAL(constant);
2698 0 : return zend_declare_class_constant(ce, name, name_length, constant TSRMLS_CC);
2699 : }
2700 :
2701 : ZEND_API int zend_declare_class_constant_long(zend_class_entry *ce, char *name, size_t name_length, long value TSRMLS_DC)
2702 2563785 : {
2703 : zval *constant;
2704 :
2705 2563785 : if (ce->type & ZEND_INTERNAL_CLASS) {
2706 2563785 : constant = malloc(sizeof(zval));
2707 : } else {
2708 0 : ALLOC_ZVAL(constant);
2709 : }
2710 2563785 : ZVAL_LONG(constant, value);
2711 2563785 : INIT_PZVAL(constant);
2712 2563785 : return zend_declare_class_constant(ce, name, name_length, constant TSRMLS_CC);
2713 : }
2714 :
2715 : ZEND_API int zend_declare_class_constant_bool(zend_class_entry *ce, char *name, size_t name_length, zend_bool value TSRMLS_DC)
2716 0 : {
2717 : zval *constant;
2718 :
2719 0 : if (ce->type & ZEND_INTERNAL_CLASS) {
2720 0 : constant = malloc(sizeof(zval));
2721 : } else {
2722 0 : ALLOC_ZVAL(constant);
2723 : }
2724 0 : ZVAL_BOOL(constant, value);
2725 0 : INIT_PZVAL(constant);
2726 0 : return zend_declare_class_constant(ce, name, name_length, constant TSRMLS_CC);
2727 : }
2728 :
2729 : ZEND_API int zend_declare_class_constant_double(zend_class_entry *ce, char *name, size_t name_length, double value TSRMLS_DC)
2730 0 : {
2731 : zval *constant;
2732 :
2733 0 : if (ce->type & ZEND_INTERNAL_CLASS) {
2734 0 : constant = malloc(sizeof(zval));
2735 : } else {
2736 0 : ALLOC_ZVAL(constant);
2737 : }
2738 0 : ZVAL_DOUBLE(constant, value);
2739 0 : INIT_PZVAL(constant);
2740 0 : return zend_declare_class_constant(ce, name, name_length, constant TSRMLS_CC);
2741 : }
2742 :
2743 : ZEND_API int zend_declare_class_constant_stringl(zend_class_entry *ce, char *name, size_t name_length, char *value, size_t value_length TSRMLS_DC)
2744 162780 : {
2745 : zval *constant;
2746 :
2747 162780 : if (ce->type & ZEND_INTERNAL_CLASS) {
2748 162780 : constant = malloc(sizeof(zval));
2749 162780 : ZVAL_STRINGL(constant, zend_strndup(value, value_length), value_length, 0);
2750 : } else {
2751 0 : ALLOC_ZVAL(constant);
2752 0 : ZVAL_STRINGL(constant, value, value_length, 1);
2753 : }
2754 162780 : INIT_PZVAL(constant);
2755 162780 : return zend_declare_class_constant(ce, name, name_length, constant TSRMLS_CC);
2756 : }
2757 :
2758 : ZEND_API int zend_declare_class_constant_string(zend_class_entry *ce, char *name, size_t name_length, char *value TSRMLS_DC)
2759 0 : {
2760 0 : return zend_declare_class_constant_stringl(ce, name, name_length, value, strlen(value) TSRMLS_CC);
2761 : }
2762 :
2763 : ZEND_API void zend_update_property(zend_class_entry *scope, zval *object, char *name, int name_length, zval *value TSRMLS_DC)
2764 4803 : {
2765 : zval *property;
2766 4803 : zend_class_entry *old_scope = EG(scope);
2767 :
2768 4803 : EG(scope) = scope;
2769 :
2770 4803 : if (!Z_OBJ_HT_P(object)->write_property) {
2771 : char *class_name;
2772 : zend_uint class_name_len;
2773 :
2774 0 : zend_get_object_classname(object, &class_name, &class_name_len TSRMLS_CC);
2775 :
2776 0 : zend_error(E_CORE_ERROR, "Property %s of class %s cannot be updated", name, class_name);
2777 : }
2778 4803 : MAKE_STD_ZVAL(property);
2779 4803 : ZVAL_STRINGL(property, name, name_length, 1);
2780 4803 : Z_OBJ_HT_P(object)->write_property(object, property, value TSRMLS_CC);
2781 4798 : zval_ptr_dtor(&property);
2782 :
2783 4798 : EG(scope) = old_scope;
2784 4798 : }
2785 :
2786 : ZEND_API void zend_update_property_null(zend_class_entry *scope, zval *object, char *name, int name_length TSRMLS_DC)
2787 0 : {
2788 : zval *tmp;
2789 :
2790 0 : ALLOC_ZVAL(tmp);
2791 0 : tmp->is_ref = 0;
2792 0 : tmp->refcount = 0;
2793 0 : ZVAL_NULL(tmp);
2794 0 : zend_update_property(scope, object, name, name_length, tmp TSRMLS_CC);
2795 0 : }
2796 :
2797 : ZEND_API void zend_update_property_bool(zend_class_entry *scope, zval *object, char *name, int name_length, long value TSRMLS_DC)
2798 0 : {
2799 : zval *tmp;
2800 :
2801 0 : ALLOC_ZVAL(tmp);
2802 0 : tmp->is_ref = 0;
2803 0 : tmp->refcount = 0;
2804 0 : ZVAL_BOOL(tmp, value);
2805 0 : zend_update_property(scope, object, name, name_length, tmp TSRMLS_CC);
2806 0 : }
2807 :
2808 : ZEND_API void zend_update_property_long(zend_class_entry *scope, zval *object, char *name, int name_length, long value TSRMLS_DC)
2809 1201 : {
2810 : zval *tmp;
2811 :
2812 1201 : ALLOC_ZVAL(tmp);
2813 1201 : tmp->is_ref = 0;
2814 1201 : tmp->refcount = 0;
2815 1201 : ZVAL_LONG(tmp, value);
2816 1201 : zend_update_property(scope, object, name, name_length, tmp TSRMLS_CC);
2817 1201 : }
2818 :
2819 : ZEND_API void zend_update_property_double(zend_class_entry *scope, zval *object, char *name, int name_length, double value TSRMLS_DC)
2820 0 : {
2821 : zval *tmp;
2822 :
2823 0 : ALLOC_ZVAL(tmp);
2824 0 : tmp->is_ref = 0;
2825 0 : tmp->refcount = 0;
2826 0 : ZVAL_DOUBLE(tmp, value);
2827 0 : zend_update_property(scope, object, name, name_length, tmp TSRMLS_CC);
2828 0 : }
2829 :
2830 : ZEND_API void zend_update_property_string(zend_class_entry *scope, zval *object, char *name, int name_length, char *value TSRMLS_DC)
2831 2062 : {
2832 : zval *tmp;
2833 :
2834 2062 : ALLOC_ZVAL(tmp);
2835 2062 : tmp->is_ref = 0;
2836 2062 : tmp->refcount = 0;
2837 2062 : ZVAL_STRING(tmp, value, 1);
2838 2062 : zend_update_property(scope, object, name, name_length, tmp TSRMLS_CC);
2839 2062 : }
2840 :
2841 : ZEND_API void zend_update_property_stringl(zend_class_entry *scope, zval *object, char *name, int name_length, char *value, int value_len TSRMLS_DC)
2842 0 : {
2843 : zval *tmp;
2844 :
2845 0 : ALLOC_ZVAL(tmp);
2846 0 : tmp->is_ref = 0;
2847 0 : tmp->refcount = 0;
2848 0 : ZVAL_STRINGL(tmp, value, value_len, 1);
2849 0 : zend_update_property(scope, object, name, name_length, tmp TSRMLS_CC);
2850 0 : }
2851 :
2852 : ZEND_API int zend_update_static_property(zend_class_entry *scope, char *name, int name_length, zval *value TSRMLS_DC)
2853 0 : {
2854 : zval **property;
2855 0 : zend_class_entry *old_scope = EG(scope);
2856 :
2857 0 : EG(scope) = scope;
2858 0 : property = zend_std_get_static_property(scope, name, name_length, 0 TSRMLS_CC);
2859 0 : EG(scope) = old_scope;
2860 0 : if (!property) {
2861 0 : return FAILURE;
2862 : } else {
2863 0 : if (*property != value) {
2864 0 : if (PZVAL_IS_REF(*property)) {
2865 0 : zval_dtor(*property);
2866 0 : Z_TYPE_PP(property) = Z_TYPE_P(value);
2867 0 : (*property)->value = value->value;
2868 0 : if (value->refcount > 0) {
2869 0 : zval_copy_ctor(*property);
2870 : }
2871 : } else {
2872 0 : zval *garbage = *property;
2873 :
2874 0 : value->refcount++;
2875 0 : if (PZVAL_IS_REF(value)) {
2876 0 : SEPARATE_ZVAL(&value);
2877 : }
2878 0 : *property = value;
2879 0 : zval_ptr_dtor(&garbage);
2880 : }
2881 : }
2882 0 : return SUCCESS;
2883 : }
2884 : }
2885 :
2886 : ZEND_API int zend_update_static_property_null(zend_class_entry *scope, char *name, int name_length TSRMLS_DC)
2887 0 : {
2888 : zval *tmp;
2889 :
2890 0 : ALLOC_ZVAL(tmp);
2891 0 : tmp->is_ref = 0;
2892 0 : tmp->refcount = 0;
2893 0 : ZVAL_NULL(tmp);
2894 0 : return zend_update_static_property(scope, name, name_length, tmp TSRMLS_CC);
2895 : }
2896 :
2897 : ZEND_API int zend_update_static_property_bool(zend_class_entry *scope, char *name, int name_length, long value TSRMLS_DC)
2898 0 : {
2899 : zval *tmp;
2900 :
2901 0 : ALLOC_ZVAL(tmp);
2902 0 : tmp->is_ref = 0;
2903 0 : tmp->refcount = 0;
2904 0 : ZVAL_BOOL(tmp, value);
2905 0 : return zend_update_static_property(scope, name, name_length, tmp TSRMLS_CC);
2906 : }
2907 :
2908 : ZEND_API int zend_update_static_property_long(zend_class_entry *scope, char *name, int name_length, long value TSRMLS_DC)
2909 0 : {
2910 : zval *tmp;
2911 :
2912 0 : ALLOC_ZVAL(tmp);
2913 0 : tmp->is_ref = 0;
2914 0 : tmp->refcount = 0;
2915 0 : ZVAL_LONG(tmp, value);
2916 0 : return zend_update_static_property(scope, name, name_length, tmp TSRMLS_CC);
2917 : }
2918 :
2919 : ZEND_API int zend_update_static_property_double(zend_class_entry *scope, char *name, int name_length, double value TSRMLS_DC)
2920 0 : {
2921 : zval *tmp;
2922 :
2923 0 : ALLOC_ZVAL(tmp);
2924 0 : tmp->is_ref = 0;
2925 0 : tmp->refcount = 0;
2926 0 : ZVAL_DOUBLE(tmp, value);
2927 0 : return zend_update_static_property(scope, name, name_length, tmp TSRMLS_CC);
2928 : }
2929 :
2930 : ZEND_API int zend_update_static_property_string(zend_class_entry *scope, char *name, int name_length, char *value TSRMLS_DC)
2931 0 : {
2932 : zval *tmp;
2933 :
2934 0 : ALLOC_ZVAL(tmp);
2935 0 : tmp->is_ref = 0;
2936 0 : tmp->refcount = 0;
2937 0 : ZVAL_STRING(tmp, value, 1);
2938 0 : return zend_update_static_property(scope, name, name_length, tmp TSRMLS_CC);
2939 : }
2940 :
2941 : ZEND_API int zend_update_static_property_stringl(zend_class_entry *scope, char *name, int name_length, char *value, int value_len TSRMLS_DC)
2942 0 : {
2943 : zval *tmp;
2944 :
2945 0 : ALLOC_ZVAL(tmp);
2946 0 : tmp->is_ref = 0;
2947 0 : tmp->refcount = 0;
2948 0 : ZVAL_STRINGL(tmp, value, value_len, 1);
2949 0 : return zend_update_static_property(scope, name, name_length, tmp TSRMLS_CC);
2950 : }
2951 :
2952 : ZEND_API zval *zend_read_property(zend_class_entry *scope, zval *object, char *name, int name_length, zend_bool silent TSRMLS_DC)
2953 730 : {
2954 : zval *property, *value;
2955 730 : zend_class_entry *old_scope = EG(scope);
2956 :
2957 730 : EG(scope) = scope;
2958 :
2959 730 : if (!Z_OBJ_HT_P(object)->read_property) {
2960 : char *class_name;
2961 : zend_uint class_name_len;
2962 :
2963 0 : zend_get_object_classname(object, &class_name, &class_name_len TSRMLS_CC);
2964 0 : zend_error(E_CORE_ERROR, "Property %s of class %s cannot be read", name, class_name);
2965 : }
2966 :
2967 730 : MAKE_STD_ZVAL(property);
2968 730 : ZVAL_STRINGL(property, name, name_length, 1);
2969 730 : value = Z_OBJ_HT_P(object)->read_property(object, property, silent?BP_VAR_IS:BP_VAR_R TSRMLS_CC);
2970 730 : zval_ptr_dtor(&property);
2971 :
2972 730 : EG(scope) = old_scope;
2973 730 : return value;
2974 : }
2975 :
2976 : ZEND_API zval *zend_read_static_property(zend_class_entry *scope, char *name, int name_length, zend_bool silent TSRMLS_DC)
2977 0 : {
2978 : zval **property;
2979 0 : zend_class_entry *old_scope = EG(scope);
2980 :
2981 0 : EG(scope) = scope;
2982 0 : property = zend_std_get_static_property(scope, name, name_length, silent TSRMLS_CC);
2983 0 : EG(scope) = old_scope;
2984 :
2985 0 : return property?*property:NULL;
2986 : }
2987 :
2988 : /*
2989 : * Local variables:
2990 : * tab-width: 4
2991 : * c-basic-offset: 4
2992 : * indent-tabs-mode: t
2993 : * End:
2994 : */
|