- use const php_hash_ops*
[m6w6/ext-http] / http_api.c
1 /*
2 +--------------------------------------------------------------------+
3 | PECL :: http |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2004-2006, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
11 */
12
13 /* $Id$ */
14
15 #define HTTP_WANT_SAPI
16 #include "php_http.h"
17
18 #include "php_output.h"
19 #include "ext/standard/url.h"
20
21 #include "php_http_api.h"
22 #include "php_http_send_api.h"
23
24 #ifdef ZEND_ENGINE_2
25 # include "php_http_exception_object.h"
26 #endif
27
28 PHP_MINIT_FUNCTION(http_support)
29 {
30 HTTP_LONG_CONSTANT("HTTP_SUPPORT", HTTP_SUPPORT);
31 HTTP_LONG_CONSTANT("HTTP_SUPPORT_REQUESTS", HTTP_SUPPORT_REQUESTS);
32 HTTP_LONG_CONSTANT("HTTP_SUPPORT_MAGICMIME", HTTP_SUPPORT_MAGICMIME);
33 HTTP_LONG_CONSTANT("HTTP_SUPPORT_ENCODINGS", HTTP_SUPPORT_ENCODINGS);
34 HTTP_LONG_CONSTANT("HTTP_SUPPORT_SSLREQUESTS", HTTP_SUPPORT_SSLREQUESTS);
35
36 HTTP_LONG_CONSTANT("HTTP_PARAMS_ALLOW_COMMA", HTTP_PARAMS_ALLOW_COMMA);
37 HTTP_LONG_CONSTANT("HTTP_PARAMS_ALLOW_FAILURE", HTTP_PARAMS_ALLOW_FAILURE);
38 HTTP_LONG_CONSTANT("HTTP_PARAMS_RAISE_ERROR", HTTP_PARAMS_RAISE_ERROR);
39 HTTP_LONG_CONSTANT("HTTP_PARAMS_DEFAULT", HTTP_PARAMS_DEFAULT);
40
41 return SUCCESS;
42 }
43
44 PHP_HTTP_API long _http_support(long feature)
45 {
46 long support = HTTP_SUPPORT;
47
48 #ifdef HTTP_HAVE_CURL
49 support |= HTTP_SUPPORT_REQUESTS;
50 # ifdef HTTP_HAVE_SSL
51 support |= HTTP_SUPPORT_SSLREQUESTS;
52 # endif
53 #endif
54 #ifdef HTTP_HAVE_MAGIC
55 support |= HTTP_SUPPORT_MAGICMIME;
56 #endif
57 #ifdef HTTP_HAVE_ZLIB
58 support |= HTTP_SUPPORT_ENCODINGS;
59 #endif
60
61 if (feature) {
62 return (feature == (support & feature));
63 }
64 return support;
65 }
66
67 /* char *pretty_key(char *, size_t, zend_bool, zend_bool) */
68 char *_http_pretty_key(char *key, size_t key_len, zend_bool uctitle, zend_bool xhyphen)
69 {
70 size_t i;
71 int wasalpha;
72
73 if (key && key_len) {
74 if ((wasalpha = HTTP_IS_CTYPE(alpha, key[0]))) {
75 key[0] = (char) (uctitle ? HTTP_TO_CTYPE(upper, key[0]) : HTTP_TO_CTYPE(lower, key[0]));
76 }
77 for (i = 1; i < key_len; i++) {
78 if (HTTP_IS_CTYPE(alpha, key[i])) {
79 key[i] = (char) (((!wasalpha) && uctitle) ? HTTP_TO_CTYPE(upper, key[i]) : HTTP_TO_CTYPE(lower, key[i]));
80 wasalpha = 1;
81 } else {
82 if (xhyphen && (key[i] == '_')) {
83 key[i] = '-';
84 }
85 wasalpha = 0;
86 }
87 }
88 }
89 return key;
90 }
91 /* }}} */
92
93 /* {{{ void http_error(long, long, char*) */
94 void _http_error_ex(long type TSRMLS_DC, long code, const char *format, ...)
95 {
96 va_list args;
97
98 va_start(args, format);
99 #ifdef ZEND_ENGINE_2
100 if ((type == E_THROW) || (PG(error_handling) == EH_THROW)) {
101 char *message;
102 zend_class_entry *ce = http_exception_get_for_code(code);
103
104 http_try {
105 vspprintf(&message, 0, format, args);
106 zend_throw_exception(ce, message, code TSRMLS_CC);
107 efree(message);
108 } http_catch(PG(exception_class) ? PG(exception_class) : HTTP_EX_DEF_CE);
109 } else
110 #endif
111 php_verror(NULL, "", type, format, args TSRMLS_CC);
112 va_end(args);
113 }
114 /* }}} */
115
116 #ifdef ZEND_ENGINE_2
117 static inline void copy_bt_args(zval *from, zval *to TSRMLS_DC)
118 {
119 zval **args, **trace_0, *old_trace_0, *trace = NULL;
120
121 if ((trace = zend_read_property(ZEND_EXCEPTION_GET_DEFAULT(), from, "trace", lenof("trace"), 0 TSRMLS_CC))) {
122 if (Z_TYPE_P(trace) == IS_ARRAY && SUCCESS == zend_hash_index_find(Z_ARRVAL_P(trace), 0, (void *) &trace_0)) {
123 old_trace_0 = *trace_0;
124 if (Z_TYPE_PP(trace_0) == IS_ARRAY && SUCCESS == zend_hash_find(Z_ARRVAL_PP(trace_0), "args", sizeof("args"), (void *) &args)) {
125 if ((trace = zend_read_property(ZEND_EXCEPTION_GET_DEFAULT(), to, "trace", lenof("trace"), 0 TSRMLS_CC))) {
126 if (Z_TYPE_P(trace) == IS_ARRAY && SUCCESS == zend_hash_index_find(Z_ARRVAL_P(trace), 0, (void *) &trace_0)) {
127 ZVAL_ADDREF(*args);
128 add_assoc_zval(*trace_0, "args", *args);
129 }
130 }
131 }
132 }
133 }
134 }
135
136 /* {{{ zval *http_exception_wrap(zval *, zval *, zend_class_entry *) */
137 zval *_http_exception_wrap(zval *old_exception, zval *new_exception, zend_class_entry *ce TSRMLS_DC)
138 {
139 int inner = 1;
140 char *message;
141 zval *sub_exception, *tmp_exception;
142
143 if (!new_exception) {
144 MAKE_STD_ZVAL(new_exception);
145 object_init_ex(new_exception, ce);
146
147 zend_update_property(ce, new_exception, "innerException", lenof("innerException"), old_exception TSRMLS_CC);
148 copy_bt_args(old_exception, new_exception TSRMLS_CC);
149
150 sub_exception = old_exception;
151
152 while ((sub_exception = zend_read_property(Z_OBJCE_P(sub_exception), sub_exception, "innerException", lenof("innerException"), 0 TSRMLS_CC)) && Z_TYPE_P(sub_exception) == IS_OBJECT) {
153 ++inner;
154 }
155
156 spprintf(&message, 0, "Exception caused by %d inner exception(s)", inner);
157 zend_update_property_string(ZEND_EXCEPTION_GET_DEFAULT(), new_exception, "message", lenof("message"), message TSRMLS_CC);
158 efree(message);
159 } else {
160 sub_exception = new_exception;
161 tmp_exception = new_exception;
162
163 while ((tmp_exception = zend_read_property(Z_OBJCE_P(tmp_exception), tmp_exception, "innerException", lenof("innerException"), 0 TSRMLS_CC)) && Z_TYPE_P(tmp_exception) == IS_OBJECT) {
164 sub_exception = tmp_exception;
165 }
166
167 zend_update_property(Z_OBJCE_P(sub_exception), sub_exception, "innerException", lenof("innerException"), old_exception TSRMLS_CC);
168 copy_bt_args(old_exception, new_exception TSRMLS_CC);
169 copy_bt_args(old_exception, sub_exception TSRMLS_CC);
170 }
171
172 zval_ptr_dtor(&old_exception);
173 return new_exception;
174 }
175 /* }}} */
176
177 /* {{{ STATUS http_object_new(zend_object_value *, const char *, uint, http_object_new_t, zend_class_entry *, void *, void **) */
178 STATUS _http_object_new(zend_object_value *ov, const char *cname_str, uint cname_len, http_object_new_t create, zend_class_entry *parent_ce, void *intern_ptr, void **obj_ptr TSRMLS_DC)
179 {
180 zend_class_entry *ce = parent_ce;
181
182 if (cname_str && cname_len) {
183 if (!(ce = zend_fetch_class((char *) cname_str, cname_len, ZEND_FETCH_CLASS_DEFAULT TSRMLS_CC))) {
184 return FAILURE;
185 }
186 if (!instanceof_function(ce, parent_ce TSRMLS_CC)) {
187 http_error_ex(HE_WARNING, HTTP_E_RUNTIME, "Class %s does not extend %s", cname_str, parent_ce->name);
188 return FAILURE;
189 }
190 }
191
192 *ov = create(ce, intern_ptr, obj_ptr TSRMLS_CC);
193 return SUCCESS;
194 }
195 /* }}} */
196 #endif /* ZEND_ENGINE_2 */
197
198 /* {{{ void http_log(char *, char *, char *) */
199 void _http_log_ex(char *file, const char *ident, const char *message TSRMLS_DC)
200 {
201 time_t now;
202 struct tm nowtm;
203 char datetime[20] = {0};
204
205 now = HTTP_G->request.time;
206 strftime(datetime, sizeof(datetime), "%Y-%m-%d %H:%M:%S", php_localtime_r(&now, &nowtm));
207
208 #define HTTP_LOG_WRITE(file, type, msg) \
209 if (file && *file) { \
210 php_stream *log = php_stream_open_wrapper_ex(file, "ab", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL, HTTP_DEFAULT_STREAM_CONTEXT); \
211 \
212 if (log) { \
213 php_stream_printf(log TSRMLS_CC, "%s\t[%s]\t%s\t<%s>%s", datetime, type, msg, SG(request_info).request_uri, PHP_EOL); \
214 php_stream_close(log); \
215 } \
216 \
217 }
218
219 HTTP_LOG_WRITE(file, ident, message);
220 HTTP_LOG_WRITE(HTTP_G->log.composite, ident, message);
221 }
222 /* }}} */
223
224 static void http_ob_blackhole(char *output, uint output_len, char **handled_output, uint *handled_output_len, int mode TSRMLS_DC)
225 {
226 *handled_output = ecalloc(1,1);
227 *handled_output_len = 0;
228 }
229
230 /* {{{ STATUS http_exit(int, char*, char*) */
231 STATUS _http_exit_ex(int status, char *header, char *body, zend_bool send_header TSRMLS_DC)
232 {
233 if ( (send_header && (SUCCESS != http_send_status_header(status, header))) ||
234 (status && (SUCCESS != http_send_status(status)))) {
235 http_error_ex(HE_WARNING, HTTP_E_HEADER, "Failed to exit with status/header: %d - %s", status, STR_PTR(header));
236 STR_FREE(header);
237 STR_FREE(body);
238 return FAILURE;
239 }
240
241 if (!OG(ob_lock)) {
242 php_end_ob_buffers(0 TSRMLS_CC);
243 }
244 if ((SUCCESS == sapi_send_headers(TSRMLS_C)) && body) {
245 PHPWRITE(body, strlen(body));
246 }
247
248 switch (status) {
249 case 301: http_log(HTTP_G->log.redirect, "301-REDIRECT", header); break;
250 case 302: http_log(HTTP_G->log.redirect, "302-REDIRECT", header); break;
251 case 303: http_log(HTTP_G->log.redirect, "303-REDIRECT", header); break;
252 case 305: http_log(HTTP_G->log.redirect, "305-REDIRECT", header); break;
253 case 307: http_log(HTTP_G->log.redirect, "307-REDIRECT", header); break;
254 case 304: http_log(HTTP_G->log.cache, "304-CACHE", header); break;
255 case 404: http_log(HTTP_G->log.not_found, "404-NOTFOUND", NULL); break;
256 case 405: http_log(HTTP_G->log.allowed_methods, "405-ALLOWED", header); break;
257 default: http_log(NULL, header, body); break;
258 }
259
260 STR_FREE(header);
261 STR_FREE(body);
262
263 if (HTTP_G->force_exit) {
264 zend_bailout();
265 } else {
266 php_ob_set_internal_handler(http_ob_blackhole, 4096, "blackhole", 0 TSRMLS_CC);
267 }
268
269 return SUCCESS;
270 }
271 /* }}} */
272
273 /* {{{ STATUS http_check_method(char *) */
274 STATUS _http_check_method_ex(const char *method, const char *methods)
275 {
276 const char *found;
277
278 if ( (found = strstr(methods, method)) &&
279 (found == method || !HTTP_IS_CTYPE(alpha, found[-1])) &&
280 (strlen(found) >= strlen(method) && !HTTP_IS_CTYPE(alpha, found[strlen(method)]))) {
281 return SUCCESS;
282 }
283 return FAILURE;
284 }
285 /* }}} */
286
287 /* {{{ zval *http_get_server_var_ex(char *, size_t) */
288 PHP_HTTP_API zval *_http_get_server_var_ex(const char *key, size_t key_len, zend_bool check TSRMLS_DC)
289 {
290 zval **hsv, **var;
291 char *env;
292
293 /* if available, this is a lot faster than accessing $_SERVER */
294 if (sapi_module.getenv) {
295 if ((!(env = sapi_module.getenv((char *) key, key_len TSRMLS_CC))) || (check && !*env)) {
296 return NULL;
297 }
298 if (HTTP_G->server_var) {
299 zval_ptr_dtor(&HTTP_G->server_var);
300 }
301 MAKE_STD_ZVAL(HTTP_G->server_var);
302 ZVAL_STRING(HTTP_G->server_var, env, 1);
303 return HTTP_G->server_var;
304 }
305
306 #ifdef ZEND_ENGINE_2
307 zend_is_auto_global("_SERVER", lenof("_SERVER") TSRMLS_CC);
308 #endif
309
310 if ((SUCCESS != zend_hash_find(&EG(symbol_table), "_SERVER", sizeof("_SERVER"), (void *) &hsv)) || (Z_TYPE_PP(hsv) != IS_ARRAY)) {
311 return NULL;
312 }
313 if ((SUCCESS != zend_hash_find(Z_ARRVAL_PP(hsv), (char *) key, key_len + 1, (void *) &var))) {
314 return NULL;
315 }
316 if (check && !((Z_TYPE_PP(var) == IS_STRING) && Z_STRVAL_PP(var) && Z_STRLEN_PP(var))) {
317 return NULL;
318 }
319 return *var;
320 }
321 /* }}} */
322
323 /* {{{ STATUS http_get_request_body(char **, size_t *) */
324 PHP_HTTP_API STATUS _http_get_request_body_ex(char **body, size_t *length, zend_bool dup TSRMLS_DC)
325 {
326 *length = 0;
327 *body = NULL;
328
329 if (SG(request_info).raw_post_data) {
330 *length = SG(request_info).raw_post_data_length;
331 *body = SG(request_info).raw_post_data;
332
333 if (dup) {
334 *body = estrndup(*body, *length);
335 }
336 return SUCCESS;
337 } else if (sapi_module.read_post && !HTTP_G->read_post_data) {
338 char buf[4096];
339 int len;
340
341 HTTP_G->read_post_data = 1;
342
343 while (0 < (len = sapi_module.read_post(buf, sizeof(buf) TSRMLS_CC))) {
344 *body = erealloc(*body, *length + len + 1);
345 memcpy(*body + *length, buf, len);
346 *length += len;
347 (*body)[*length] = '\0';
348 }
349
350 /* check for error */
351 if (len < 0) {
352 STR_FREE(*body);
353 *length = 0;
354 return FAILURE;
355 }
356
357 SG(request_info).raw_post_data = *body;
358 SG(request_info).raw_post_data_length = *length;
359
360 if (dup) {
361 *body = estrndup(*body, *length);
362 }
363 return SUCCESS;
364 }
365
366 return FAILURE;
367 }
368 /* }}} */
369
370 /* {{{ php_stream *http_get_request_body_stream(void) */
371 PHP_HTTP_API php_stream *_http_get_request_body_stream(TSRMLS_D)
372 {
373 php_stream *s = NULL;
374
375 if (SG(request_info).raw_post_data) {
376 s = php_stream_open_wrapper("php://input", "rb", 0, NULL);
377 } else if (sapi_module.read_post && !HTTP_G->read_post_data) {
378 HTTP_G->read_post_data = 1;
379
380 if ((s = php_stream_temp_new())) {
381 char buf[4096];
382 int len;
383
384 while (0 < (len = sapi_module.read_post(buf, sizeof(buf) TSRMLS_CC))) {
385 php_stream_write(s, buf, len);
386 }
387
388 if (len < 0) {
389 php_stream_close(s);
390 s = NULL;
391 } else {
392 php_stream_rewind(s);
393 }
394 }
395 }
396
397 return s;
398 }
399 /* }}} */
400
401 /* {{{ void http_parse_params_default_callback(...) */
402 PHP_HTTP_API void _http_parse_params_default_callback(void *arg, const char *key, int keylen, const char *val, int vallen TSRMLS_DC)
403 {
404 char *kdup;
405 zval tmp, *entry;
406 HashTable *ht = (HashTable *) arg;
407
408 if (ht) {
409 INIT_ZARR(tmp, ht);
410
411 if (vallen) {
412 MAKE_STD_ZVAL(entry);
413 array_init(entry);
414 if (keylen) {
415 kdup = estrndup(key, keylen);
416 add_assoc_stringl_ex(entry, kdup, keylen + 1, (char *) val, vallen, 1);
417 efree(kdup);
418 } else {
419 add_next_index_stringl(entry, (char *) val, vallen, 1);
420 }
421 add_next_index_zval(&tmp, entry);
422 } else {
423 add_next_index_stringl(&tmp, (char *) key, keylen, 1);
424 }
425 }
426 }
427 /* }}} */
428
429 /* {{{ STATUS http_parse_params(const char *, HashTable *) */
430 PHP_HTTP_API STATUS _http_parse_params_ex(const char *param, int flags, http_parse_params_callback cb, void *cb_arg TSRMLS_DC)
431 {
432 #define ST_QUOTE 1
433 #define ST_VALUE 2
434 #define ST_KEY 3
435 #define ST_ASSIGN 4
436 #define ST_ADD 5
437
438 int st = ST_KEY, keylen = 0, vallen = 0;
439 char *s, *c, *key = NULL, *val = NULL;
440
441 for(c = s = estrdup(param);;) {
442 continued:
443 #if 0
444 {
445 char *tk = NULL, *tv = NULL;
446
447 if (key) {
448 if (keylen) {
449 tk= estrndup(key, keylen);
450 } else {
451 tk = ecalloc(1, 7);
452 memcpy(tk, key, 3);
453 tk[3]='.'; tk[4]='.'; tk[5]='.';
454 }
455 }
456 if (val) {
457 if (vallen) {
458 tv = estrndup(val, vallen);
459 } else {
460 tv = ecalloc(1, 7);
461 memcpy(tv, val, 3);
462 tv[3]='.'; tv[4]='.'; tv[5]='.';
463 }
464 }
465 fprintf(stderr, "[%6s] %c \"%s=%s\"\n",
466 (
467 st == ST_QUOTE ? "QUOTE" :
468 st == ST_VALUE ? "VALUE" :
469 st == ST_KEY ? "KEY" :
470 st == ST_ASSIGN ? "ASSIGN" :
471 st == ST_ADD ? "ADD":
472 "HUH?"
473 ), *c?*c:'0', tk, tv
474 );
475 STR_FREE(tk); STR_FREE(tv);
476 }
477 #endif
478 switch (st) {
479 case ST_QUOTE:
480 quote:
481 if (*c == '"') {
482 if (*(c-1) == '\\') {
483 memmove(c-1, c, strlen(c)+1);
484 goto quote;
485 } else {
486 goto add;
487 }
488 } else {
489 if (!val) {
490 val = c;
491 }
492 if (!*c) {
493 --val;
494 st = ST_ADD;
495 }
496 }
497 break;
498
499 case ST_VALUE:
500 switch (*c) {
501 case '"':
502 if (!val) {
503 st = ST_QUOTE;
504 }
505 break;
506
507 case ' ':
508 break;
509
510 case ';':
511 case '\0':
512 goto add;
513 break;
514 case ',':
515 if (flags & HTTP_PARAMS_ALLOW_COMMA) {
516 goto add;
517 }
518 default:
519 if (!val) {
520 val = c;
521 }
522 break;
523 }
524 break;
525
526 case ST_KEY:
527 switch (*c) {
528 case ',':
529 if (flags & HTTP_PARAMS_ALLOW_COMMA) {
530 goto allow_comma;
531 }
532 case '\r':
533 case '\n':
534 case '\t':
535 case '\013':
536 case '\014':
537 goto failure;
538 break;
539
540 case '=':
541 if (key) {
542 keylen = c - key;
543 st = ST_VALUE;
544 } else {
545 goto failure;
546 }
547 break;
548
549 case ' ':
550 if (key) {
551 keylen = c - key;
552 st = ST_ASSIGN;
553 }
554 break;
555
556 case ';':
557 case '\0':
558 allow_comma:
559 if (key) {
560 keylen = c-- - key;
561 st = ST_ADD;
562 }
563 break;
564
565 default:
566 if (!key) {
567 key = c;
568 }
569 break;
570 }
571 break;
572
573 case ST_ASSIGN:
574 if (*c == '=') {
575 st = ST_VALUE;
576 } else if (!*c || *c == ';' || ((flags & HTTP_PARAMS_ALLOW_COMMA) && *c == ',')) {
577 st = ST_ADD;
578 } else if (*c != ' ') {
579 goto failure;
580 }
581 break;
582
583 case ST_ADD:
584 add:
585 if (val) {
586 vallen = c - val;
587 if (st != ST_QUOTE) {
588 while (val[vallen-1] == ' ') --vallen;
589 }
590 } else {
591 val = "";
592 vallen = 0;
593 }
594
595 cb(cb_arg, key, keylen, val, vallen TSRMLS_CC);
596
597 st = ST_KEY;
598 key = val = NULL;
599 keylen = vallen = 0;
600 break;
601 }
602 if (*c) {
603 ++c;
604 } else if (st == ST_ADD) {
605 goto add;
606 } else {
607 break;
608 }
609 }
610
611 efree(s);
612 return SUCCESS;
613
614 failure:
615 if (flags & HTTP_PARAMS_RAISE_ERROR) {
616 http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Unexpected character (%c) at pos %tu of %zu", *c, c-s, strlen(s));
617 }
618 if (flags & HTTP_PARAMS_ALLOW_FAILURE) {
619 if (st == ST_KEY) {
620 if (key) {
621 keylen = c - key;
622 } else {
623 key = c;
624 }
625 } else {
626 --c;
627 }
628 st = ST_ADD;
629 goto continued;
630 }
631 efree(s);
632 return FAILURE;
633 }
634 /* }}} */
635
636 /* {{{ array_join */
637 int apply_array_append_func(void *pDest, int num_args, va_list args, zend_hash_key *hash_key)
638 {
639 int flags;
640 char *key = NULL;
641 HashTable *dst;
642 zval **data = NULL, **value = (zval **) pDest;
643
644 dst = va_arg(args, HashTable *);
645 flags = va_arg(args, int);
646
647 if ((!(flags & ARRAY_JOIN_STRONLY)) || hash_key->nKeyLength) {
648 if ((flags & ARRAY_JOIN_PRETTIFY) && hash_key->nKeyLength) {
649 key = pretty_key(estrndup(hash_key->arKey, hash_key->nKeyLength - 1), hash_key->nKeyLength - 1, 1, 1);
650 zend_hash_find(dst, key, hash_key->nKeyLength, (void *) &data);
651 } else {
652 zend_hash_quick_find(dst, hash_key->arKey, hash_key->nKeyLength, hash_key->h, (void *) &data);
653 }
654
655 ZVAL_ADDREF(*value);
656 if (data) {
657 if (Z_TYPE_PP(data) != IS_ARRAY) {
658 convert_to_array(*data);
659 }
660 add_next_index_zval(*data, *value);
661 } else if (key) {
662 zend_hash_add(dst, key, hash_key->nKeyLength, value, sizeof(zval *), NULL);
663 } else {
664 zend_hash_quick_add(dst, hash_key->arKey, hash_key->nKeyLength, hash_key->h, value, sizeof(zval *), NULL);
665 }
666
667 if (key) {
668 efree(key);
669 }
670 }
671
672 return ZEND_HASH_APPLY_KEEP;
673 }
674
675 int apply_array_merge_func(void *pDest, int num_args, va_list args, zend_hash_key *hash_key)
676 {
677 int flags;
678 char *key = NULL;
679 HashTable *dst;
680 zval **value = (zval **) pDest;
681
682 dst = va_arg(args, HashTable *);
683 flags = va_arg(args, int);
684
685 if ((!(flags & ARRAY_JOIN_STRONLY)) || hash_key->nKeyLength) {
686 ZVAL_ADDREF(*value);
687 if ((flags & ARRAY_JOIN_PRETTIFY) && hash_key->nKeyLength) {
688 key = pretty_key(estrndup(hash_key->arKey, hash_key->nKeyLength - 1), hash_key->nKeyLength - 1, 1, 1);
689 zend_hash_update(dst, key, hash_key->nKeyLength, (void *) value, sizeof(zval *), NULL);
690 efree(key);
691 } else {
692 zend_hash_quick_update(dst, hash_key->arKey, hash_key->nKeyLength, hash_key->h, (void *) value, sizeof(zval *), NULL);
693 }
694 }
695
696 return ZEND_HASH_APPLY_KEEP;
697 }
698 /* }}} */
699
700 /*
701 * Local variables:
702 * tab-width: 4
703 * c-basic-offset: 4
704 * End:
705 * vim600: noet sw=4 ts=4 fdm=marker
706 * vim<600: noet sw=4 ts=4
707 */
708