2 +--------------------------------------------------------------------+
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-2014, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
13 #include "php_http_api.h"
14 #include "php_variables.h"
16 PHP_RSHUTDOWN_FUNCTION(http_env
)
18 if (PHP_HTTP_G
->env
.request
.headers
) {
19 zend_hash_destroy(PHP_HTTP_G
->env
.request
.headers
);
20 FREE_HASHTABLE(PHP_HTTP_G
->env
.request
.headers
);
21 PHP_HTTP_G
->env
.request
.headers
= NULL
;
23 if (PHP_HTTP_G
->env
.request
.body
) {
24 php_http_message_body_free(&PHP_HTTP_G
->env
.request
.body
);
27 if (PHP_HTTP_G
->env
.server_var
) {
28 zval_ptr_dtor(&PHP_HTTP_G
->env
.server_var
);
29 PHP_HTTP_G
->env
.server_var
= NULL
;
35 void php_http_env_get_request_headers(HashTable
*headers TSRMLS_DC
)
37 php_http_array_hashkey_t key
= php_http_array_hashkey_init(0);
41 if (!PHP_HTTP_G
->env
.request
.headers
) {
42 ALLOC_HASHTABLE(PHP_HTTP_G
->env
.request
.headers
);
43 zend_hash_init(PHP_HTTP_G
->env
.request
.headers
, 0, NULL
, ZVAL_PTR_DTOR
, 0);
45 zend_is_auto_global("_SERVER", lenof("_SERVER") TSRMLS_CC
);
47 if (SUCCESS
== zend_hash_find(&EG(symbol_table
), "_SERVER", sizeof("_SERVER"), (void *) &hsv
) && Z_TYPE_PP(hsv
) == IS_ARRAY
) {
48 FOREACH_KEY(pos
, *hsv
, key
) {
49 if (key
.type
== HASH_KEY_IS_STRING
&& key
.len
> 6 && *key
.str
== 'H' && !strncmp(key
.str
, "HTTP_", 5)) {
51 key
.str
= php_http_pretty_key(estrndup(key
.str
+ 5, key
.len
- 1), key
.len
- 1, 1, 1);
53 zend_hash_get_current_data_ex(Z_ARRVAL_PP(hsv
), (void *) &header
, &pos
);
55 zend_symtable_update(PHP_HTTP_G
->env
.request
.headers
, key
.str
, key
.len
, (void *) header
, sizeof(zval
*), NULL
);
58 } else if (key
.type
== HASH_KEY_IS_STRING
&& key
.len
> 9 && *key
.str
== 'C' && !strncmp(key
.str
, "CONTENT_", 8)) {
59 key
.str
= php_http_pretty_key(estrndup(key
.str
, key
.len
- 1), key
.len
- 1, 1, 1);
61 zend_hash_get_current_data_ex(Z_ARRVAL_PP(hsv
), (void *) &header
, &pos
);
63 zend_symtable_update(PHP_HTTP_G
->env
.request
.headers
, key
.str
, key
.len
, (void *) header
, sizeof(zval
*), NULL
);
72 zend_hash_copy(headers
, PHP_HTTP_G
->env
.request
.headers
, (copy_ctor_func_t
) zval_add_ref
, NULL
, sizeof(zval
*));
76 char *php_http_env_get_request_header(const char *name_str
, size_t name_len
, size_t *len
, php_http_message_t
*request TSRMLS_DC
)
78 HashTable
*request_headers
;
80 char *val
= NULL
, *key
= php_http_pretty_key(estrndup(name_str
, name_len
), name_len
, 1, 1);
83 request_headers
= &request
->hdrs
;
85 php_http_env_get_request_headers(NULL TSRMLS_CC
);
86 request_headers
= PHP_HTTP_G
->env
.request
.headers
;
89 if (SUCCESS
== zend_symtable_find(request_headers
, key
, name_len
+ 1, (void *) &zvalue
)) {
90 zval
*zcopy
= php_http_ztyp(IS_STRING
, *zvalue
);
92 val
= estrndup(Z_STRVAL_P(zcopy
), Z_STRLEN_P(zcopy
));
94 *len
= Z_STRLEN_P(zcopy
);
96 zval_ptr_dtor(&zcopy
);
104 int php_http_env_got_request_header(const char *name_str
, size_t name_len
, php_http_message_t
*request TSRMLS_DC
)
106 HashTable
*request_headers
;
107 char *key
= php_http_pretty_key(estrndup(name_str
, name_len
), name_len
, 1, 1);
111 request_headers
= &request
->hdrs
;
113 php_http_env_get_request_headers(NULL TSRMLS_CC
);
114 request_headers
= PHP_HTTP_G
->env
.request
.headers
;
116 got
= zend_symtable_exists(request_headers
, key
, name_len
+ 1);
122 zval
*php_http_env_get_superglobal(const char *key
, size_t key_len TSRMLS_DC
)
126 zend_is_auto_global(key
, key_len TSRMLS_CC
);
128 if ((SUCCESS
!= zend_hash_find(&EG(symbol_table
), key
, key_len
+ 1, (void *) &hsv
)) || (Z_TYPE_PP(hsv
) != IS_ARRAY
)) {
135 zval
*php_http_env_get_server_var(const char *key
, size_t key_len
, zend_bool check TSRMLS_DC
)
140 /* if available, this is a lot faster than accessing $_SERVER */
141 if (sapi_module
.getenv
) {
142 if ((!(env
= sapi_module
.getenv((char *) key
, key_len TSRMLS_CC
))) || (check
&& !*env
)) {
145 if (PHP_HTTP_G
->env
.server_var
) {
146 zval_ptr_dtor(&PHP_HTTP_G
->env
.server_var
);
148 MAKE_STD_ZVAL(PHP_HTTP_G
->env
.server_var
);
149 ZVAL_STRING(PHP_HTTP_G
->env
.server_var
, env
, 1);
150 return PHP_HTTP_G
->env
.server_var
;
153 if (!(hsv
= php_http_env_get_superglobal(ZEND_STRL("_SERVER") TSRMLS_CC
))) {
156 if ((SUCCESS
!= zend_symtable_find(Z_ARRVAL_P(hsv
), key
, key_len
+ 1, (void *) &var
))) {
159 if (check
&& !((Z_TYPE_PP(var
) == IS_STRING
) && Z_STRVAL_PP(var
) && Z_STRLEN_PP(var
))) {
165 php_http_message_body_t
*php_http_env_get_request_body(TSRMLS_D
)
167 if (!PHP_HTTP_G
->env
.request
.body
) {
168 php_stream
*s
= php_stream_temp_new();
169 #if PHP_VERSION_ID >= 50600
170 php_stream
*input
= php_stream_open_wrapper("php://input", "r", 0, NULL
);
172 /* php://input does not support stat */
173 php_stream_copy_to_stream_ex(input
, s
, -1, NULL
);
174 php_stream_close(input
);
176 if (SG(request_info
).post_data
|| SG(request_info
).raw_post_data
) {
177 /* php://input does not support seek() in PHP <= 5.5 */
178 if (SG(request_info
).raw_post_data
) {
179 php_stream_write(s
, SG(request_info
).raw_post_data
, SG(request_info
).raw_post_data_length
);
181 php_stream_write(s
, SG(request_info
).post_data
, SG(request_info
).post_data_length
);
183 } else if (sapi_module
.read_post
&& !SG(read_post_bytes
)) {
184 char *buf
= emalloc(4096);
187 while (0 < (len
= sapi_module
.read_post(buf
, 4096 TSRMLS_CC
))) {
188 SG(read_post_bytes
) += len
;
189 php_stream_write(s
, buf
, len
);
198 php_stream_rewind(s
);
199 PHP_HTTP_G
->env
.request
.body
= php_http_message_body_init(NULL
, s TSRMLS_CC
);
202 return PHP_HTTP_G
->env
.request
.body
;
205 const char *php_http_env_get_request_method(php_http_message_t
*request TSRMLS_DC
)
209 if (PHP_HTTP_MESSAGE_TYPE(REQUEST
, request
)) {
210 m
= request
->http
.info
.request
.method
;
212 m
= SG(request_info
).request_method
;
215 return m
? m
: "GET";
218 php_http_range_status_t
php_http_env_get_request_ranges(HashTable
*ranges
, size_t length
, php_http_message_t
*request TSRMLS_DC
)
222 long begin
= -1, end
= -1, *ptr
;
224 if (!(range
= php_http_env_get_request_header(ZEND_STRL("Range"), NULL
, request TSRMLS_CC
))) {
225 return PHP_HTTP_RANGE_NO
;
227 if (strncmp(range
, "bytes=", lenof("bytes="))) {
229 return PHP_HTTP_RANGE_NO
;
232 rp
= range
+ lenof("bytes=");
236 switch (c
= *(rp
++)) {
238 /* allow 000... - shall we? */
244 case '1': case '2': case '3':
245 case '4': case '5': case '6':
246 case '7': case '8': case '9':
248 * If the value of the pointer is already set (non-negative)
249 * then multiply its value by ten and add the current value,
250 * else initialise the pointers value with the current value
252 * This let us recognize empty fields when validating the
253 * ranges, i.e. a "-10" for begin and "12345" for the end
254 * was the following range request: "Range: bytes=0-12345";
255 * While a "-1" for begin and "12345" for the end would
256 * have been: "Range: bytes=-12345".
277 /* validate ranges */
285 return PHP_HTTP_RANGE_NO
;
293 if (length
<= (size_t) end
) {
304 if (end
== -1 || end
== -10) {
306 return PHP_HTTP_RANGE_ERR
;
308 begin
= length
- end
;
314 if (length
<= (size_t) begin
) {
316 return PHP_HTTP_RANGE_ERR
;
322 return PHP_HTTP_RANGE_ERR
;
331 if (length
<= (size_t) end
) {
333 } else if (end
< begin
) {
335 return PHP_HTTP_RANGE_ERR
;
343 MAKE_STD_ZVAL(zentry
);
345 add_index_long(zentry
, 0, begin
);
346 add_index_long(zentry
, 1, end
);
347 zend_hash_next_index_insert(ranges
, &zentry
, sizeof(zval
*), NULL
);
357 return PHP_HTTP_RANGE_NO
;
362 return PHP_HTTP_RANGE_OK
;
365 static void grab_headers(void *data
, void *arg TSRMLS_DC
)
367 php_http_buffer_appendl(PHP_HTTP_BUFFER(arg
), ((sapi_header_struct
*)data
)->header
);
368 php_http_buffer_appends(PHP_HTTP_BUFFER(arg
), PHP_HTTP_CRLF
);
371 ZEND_RESULT_CODE
php_http_env_get_response_headers(HashTable
*headers_ht TSRMLS_DC
)
373 ZEND_RESULT_CODE status
;
374 php_http_buffer_t headers
;
376 php_http_buffer_init(&headers
);
377 zend_llist_apply_with_argument(&SG(sapi_headers
).headers
, grab_headers
, &headers TSRMLS_CC
);
378 php_http_buffer_fix(&headers
);
380 status
= php_http_header_parse(headers
.data
, headers
.used
, headers_ht
, NULL
, NULL TSRMLS_CC
);
381 php_http_buffer_dtor(&headers
);
386 char *php_http_env_get_response_header(const char *name_str
, size_t name_len TSRMLS_DC
)
391 zend_hash_init(&headers
, 0, NULL
, ZVAL_PTR_DTOR
, 0);
392 if (SUCCESS
== php_http_env_get_response_headers(&headers TSRMLS_CC
)) {
394 char *key
= php_http_pretty_key(estrndup(name_str
, name_len
), name_len
, 1, 1);
396 if (SUCCESS
== zend_symtable_find(&headers
, key
, name_len
+ 1, (void *) &zvalue
)) {
397 zval
*zcopy
= php_http_ztyp(IS_STRING
, *zvalue
);
399 val
= estrndup(Z_STRVAL_P(zcopy
), Z_STRLEN_P(zcopy
));
400 zval_ptr_dtor(&zcopy
);
405 zend_hash_destroy(&headers
);
410 long php_http_env_get_response_code(TSRMLS_D
)
412 long code
= SG(sapi_headers
).http_response_code
;
413 return code
? code
: 200;
416 ZEND_RESULT_CODE
php_http_env_set_response_code(long http_code TSRMLS_DC
)
418 return sapi_header_op(SAPI_HEADER_SET_STATUS
, (void *) http_code TSRMLS_CC
);
421 ZEND_RESULT_CODE
php_http_env_set_response_status_line(long code
, php_http_version_t
*v TSRMLS_DC
)
423 sapi_header_line h
= {NULL
, 0, 0};
424 ZEND_RESULT_CODE ret
;
426 h
.line_len
= spprintf(&h
.line
, 0, "HTTP/%u.%u %ld %s", v
->major
, v
->minor
, code
, php_http_env_get_response_status_for_code(code
));
427 ret
= sapi_header_op(SAPI_HEADER_REPLACE
, (void *) &h TSRMLS_CC
);
433 ZEND_RESULT_CODE
php_http_env_set_response_protocol_version(php_http_version_t
*v TSRMLS_DC
)
435 return php_http_env_set_response_status_line(php_http_env_get_response_code(TSRMLS_C
), v TSRMLS_CC
);
438 ZEND_RESULT_CODE
php_http_env_set_response_header(long http_code
, const char *header_str
, size_t header_len
, zend_bool replace TSRMLS_DC
)
440 sapi_header_line h
= {estrndup(header_str
, header_len
), header_len
, http_code
};
441 ZEND_RESULT_CODE ret
= sapi_header_op(replace
? SAPI_HEADER_REPLACE
: SAPI_HEADER_ADD
, (void *) &h TSRMLS_CC
);
446 ZEND_RESULT_CODE
php_http_env_set_response_header_va(long http_code
, zend_bool replace
, const char *fmt
, va_list argv TSRMLS_DC
)
448 ZEND_RESULT_CODE ret
= FAILURE
;
449 sapi_header_line h
= {NULL
, 0, http_code
};
451 h
.line_len
= vspprintf(&h
.line
, 0, fmt
, argv
);
455 ret
= sapi_header_op(replace
? SAPI_HEADER_REPLACE
: SAPI_HEADER_ADD
, (void *) &h TSRMLS_CC
);
462 ZEND_RESULT_CODE
php_http_env_set_response_header_format(long http_code
, zend_bool replace TSRMLS_DC
, const char *fmt
, ...)
464 ZEND_RESULT_CODE ret
;
468 ret
= php_http_env_set_response_header_va(http_code
, replace
, fmt
, args TSRMLS_CC
);
474 ZEND_RESULT_CODE
php_http_env_set_response_header_value(long http_code
, const char *name_str
, size_t name_len
, zval
*value
, zend_bool replace TSRMLS_DC
)
477 sapi_header_line h
= {(char *) name_str
, name_len
, http_code
};
479 return sapi_header_op(SAPI_HEADER_DELETE
, (void *) &h TSRMLS_CC
);
482 if(Z_TYPE_P(value
) == IS_ARRAY
|| Z_TYPE_P(value
) == IS_OBJECT
) {
487 FOREACH_HASH_VAL(pos
, HASH_OF(value
), data_ptr
) {
488 if (SUCCESS
!= php_http_env_set_response_header_value(http_code
, name_str
, name_len
, *data_ptr
, first TSRMLS_CC
)) {
496 zval
*data
= php_http_ztyp(IS_STRING
, value
);
498 if (!Z_STRLEN_P(data
)) {
499 zval_ptr_dtor(&data
);
500 return php_http_env_set_response_header_value(http_code
, name_str
, name_len
, NULL
, replace TSRMLS_CC
);
503 ZEND_RESULT_CODE ret
;
505 if (name_len
> INT_MAX
) {
508 h
.response_code
= http_code
;
509 h
.line_len
= spprintf(&h
.line
, 0, "%.*s: %.*s", (int) name_len
, name_str
, Z_STRLEN_P(data
), Z_STRVAL_P(data
));
511 ret
= sapi_header_op(replace
? SAPI_HEADER_REPLACE
: SAPI_HEADER_ADD
, (void *) &h TSRMLS_CC
);
513 zval_ptr_dtor(&data
);
521 const char *php_http_env_get_response_status_for_code(unsigned code
)
524 #define PHP_HTTP_RESPONSE_CODE(c, s) case c: return s;
525 #include "php_http_response_codes.h"
526 #undef PHP_HTTP_RESPONSE_CODE
532 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_getRequestHeader
, 0, 0, 0)
533 ZEND_ARG_INFO(0, header_name
)
535 static PHP_METHOD(HttpEnv
, getRequestHeader
)
537 char *header_name_str
= NULL
;
538 int header_name_len
= 0;
540 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|s!", &header_name_str
, &header_name_len
)) {
543 if (header_name_str
&& header_name_len
) {
544 size_t header_length
;
545 char *header_value
= php_http_env_get_request_header(header_name_str
, header_name_len
, &header_length
, NULL TSRMLS_CC
);
548 RETURN_STRINGL(header_value
, header_length
, 0);
551 array_init(return_value
);
552 php_http_env_get_request_headers(Z_ARRVAL_P(return_value
) TSRMLS_CC
);
556 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_getRequestBody
, 0, 0, 0)
557 ZEND_ARG_INFO(0, body_class_name
)
559 static PHP_METHOD(HttpEnv
, getRequestBody
)
561 zend_object_value ov
;
562 php_http_message_body_t
*body
;
563 zend_class_entry
*class_entry
= php_http_message_body_class_entry
;
565 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|C", &class_entry
), invalid_arg
, return);
567 body
= php_http_env_get_request_body(TSRMLS_C
);
568 if (SUCCESS
== php_http_new(&ov
, class_entry
, (php_http_new_t
) php_http_message_body_object_new_ex
, php_http_message_body_class_entry
, body
, NULL TSRMLS_CC
)) {
569 php_http_message_body_addref(body
);
570 RETVAL_OBJVAL(ov
, 0);
574 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_getResponseStatusForCode
, 0, 0, 1)
575 ZEND_ARG_INFO(0, code
)
577 static PHP_METHOD(HttpEnv
, getResponseStatusForCode
)
582 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "l", &code
)) {
586 if ((status
= php_http_env_get_response_status_for_code(code
))) {
587 RETURN_STRING(status
, 1);
591 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_getResponseStatusForAllCodes
, 0, 0, 0)
593 static PHP_METHOD(HttpEnv
, getResponseStatusForAllCodes
)
595 if (SUCCESS
!= zend_parse_parameters_none()) {
599 array_init(return_value
);
600 #define PHP_HTTP_RESPONSE_CODE(code, status) add_index_string(return_value, code, status, 1);
601 #include "php_http_response_codes.h"
602 #undef PHP_HTTP_RESPONSE_CODE
605 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_getResponseHeader
, 0, 0, 0)
606 ZEND_ARG_INFO(0, header_name
)
608 static PHP_METHOD(HttpEnv
, getResponseHeader
)
610 char *header_name_str
= NULL
;
611 int header_name_len
= 0;
613 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|s!", &header_name_str
, &header_name_len
)) {
616 if (header_name_str
&& header_name_len
) {
617 char *header_value
= php_http_env_get_response_header(header_name_str
, header_name_len TSRMLS_CC
);
620 RETURN_STRING(header_value
, 0);
623 array_init(return_value
);
624 php_http_env_get_response_headers(Z_ARRVAL_P(return_value
) TSRMLS_CC
);
628 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_getResponseCode
, 0, 0, 0)
630 static PHP_METHOD(HttpEnv
, getResponseCode
)
632 if (SUCCESS
!= zend_parse_parameters_none()) {
635 RETURN_LONG(php_http_env_get_response_code(TSRMLS_C
));
638 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_setResponseHeader
, 0, 0, 1)
639 ZEND_ARG_INFO(0, header_name
)
640 ZEND_ARG_INFO(0, header_value
)
641 ZEND_ARG_INFO(0, response_code
)
642 ZEND_ARG_INFO(0, replace_header
)
644 static PHP_METHOD(HttpEnv
, setResponseHeader
)
646 char *header_name_str
;
648 zval
*header_value
= NULL
;
650 zend_bool replace_header
= 1;
652 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s|z!lb", &header_name_str
, &header_name_len
, &header_value
, &code
, &replace_header
)) {
655 RETURN_BOOL(SUCCESS
== php_http_env_set_response_header_value(code
, header_name_str
, header_name_len
, header_value
, replace_header TSRMLS_CC
));
658 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_setResponseCode
, 0, 0, 1)
659 ZEND_ARG_INFO(0, code
)
661 static PHP_METHOD(HttpEnv
, setResponseCode
)
665 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "l", &code
)) {
668 RETURN_BOOL(SUCCESS
== php_http_env_set_response_code(code TSRMLS_CC
));
671 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_negotiateLanguage
, 0, 0, 1)
672 ZEND_ARG_INFO(0, supported
)
673 ZEND_ARG_INFO(1, result_array
)
675 static PHP_METHOD(HttpEnv
, negotiateLanguage
)
677 HashTable
*supported
;
678 zval
*rs_array
= NULL
;
680 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "H|z", &supported
, &rs_array
)) {
685 array_init(rs_array
);
688 PHP_HTTP_DO_NEGOTIATE(language
, supported
, rs_array
);
691 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_negotiateCharset
, 0, 0, 1)
692 ZEND_ARG_INFO(0, supported
)
693 ZEND_ARG_INFO(1, result_array
)
695 static PHP_METHOD(HttpEnv
, negotiateCharset
)
697 HashTable
*supported
;
698 zval
*rs_array
= NULL
;
700 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "H|z", &supported
, &rs_array
)) {
705 array_init(rs_array
);
707 PHP_HTTP_DO_NEGOTIATE(charset
, supported
, rs_array
);
710 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_negotiateEncoding
, 0, 0, 1)
711 ZEND_ARG_INFO(0, supported
)
712 ZEND_ARG_INFO(1, result_array
)
714 static PHP_METHOD(HttpEnv
, negotiateEncoding
)
716 HashTable
*supported
;
717 zval
*rs_array
= NULL
;
719 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "H|z", &supported
, &rs_array
)) {
724 array_init(rs_array
);
726 PHP_HTTP_DO_NEGOTIATE(encoding
, supported
, rs_array
);
729 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_negotiateContentType
, 0, 0, 1)
730 ZEND_ARG_INFO(0, supported
)
731 ZEND_ARG_INFO(1, result_array
)
733 static PHP_METHOD(HttpEnv
, negotiateContentType
)
735 HashTable
*supported
;
736 zval
*rs_array
= NULL
;
738 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "H|z", &supported
, &rs_array
)) {
743 array_init(rs_array
);
745 PHP_HTTP_DO_NEGOTIATE(content_type
, supported
, rs_array
);
748 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_negotiate
, 0, 0, 2)
749 ZEND_ARG_INFO(0, params
)
750 ZEND_ARG_INFO(0, supported
)
751 ZEND_ARG_INFO(0, primary_type_separator
)
752 ZEND_ARG_INFO(1, result_array
)
754 static PHP_METHOD(HttpEnv
, negotiate
)
756 HashTable
*supported
, *rs
;
757 zval
*rs_array
= NULL
;
758 char *value_str
, *sep_str
= NULL
;
759 int value_len
, sep_len
= 0;
761 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "sH|s!z", &value_str
, &value_len
, &supported
, &sep_str
, &sep_len
, &rs_array
)) {
768 array_init(rs_array
);
771 if ((rs
= php_http_negotiate(value_str
, value_len
, supported
, sep_str
, sep_len TSRMLS_CC
))) {
772 PHP_HTTP_DO_NEGOTIATE_HANDLE_RESULT(rs
, supported
, rs_array
);
774 PHP_HTTP_DO_NEGOTIATE_HANDLE_DEFAULT(supported
, rs_array
);
778 static zend_function_entry php_http_env_methods
[] = {
779 PHP_ME(HttpEnv
, getRequestHeader
, ai_HttpEnv_getRequestHeader
, ZEND_ACC_PUBLIC
|ZEND_ACC_STATIC
)
780 PHP_ME(HttpEnv
, getRequestBody
, ai_HttpEnv_getRequestBody
, ZEND_ACC_PUBLIC
|ZEND_ACC_STATIC
)
782 PHP_ME(HttpEnv
, getResponseStatusForCode
, ai_HttpEnv_getResponseStatusForCode
, ZEND_ACC_PUBLIC
|ZEND_ACC_STATIC
)
783 PHP_ME(HttpEnv
, getResponseStatusForAllCodes
, ai_HttpEnv_getResponseStatusForAllCodes
, ZEND_ACC_PUBLIC
|ZEND_ACC_STATIC
)
785 PHP_ME(HttpEnv
, getResponseHeader
, ai_HttpEnv_getResponseHeader
, ZEND_ACC_PUBLIC
|ZEND_ACC_STATIC
)
786 PHP_ME(HttpEnv
, getResponseCode
, ai_HttpEnv_getResponseCode
, ZEND_ACC_PUBLIC
|ZEND_ACC_STATIC
)
787 PHP_ME(HttpEnv
, setResponseHeader
, ai_HttpEnv_setResponseHeader
, ZEND_ACC_PUBLIC
|ZEND_ACC_STATIC
)
788 PHP_ME(HttpEnv
, setResponseCode
, ai_HttpEnv_setResponseCode
, ZEND_ACC_PUBLIC
|ZEND_ACC_STATIC
)
790 PHP_ME(HttpEnv
, negotiateLanguage
, ai_HttpEnv_negotiateLanguage
, ZEND_ACC_PUBLIC
|ZEND_ACC_STATIC
)
791 PHP_ME(HttpEnv
, negotiateContentType
, ai_HttpEnv_negotiateContentType
, ZEND_ACC_PUBLIC
|ZEND_ACC_STATIC
)
792 PHP_ME(HttpEnv
, negotiateEncoding
, ai_HttpEnv_negotiateEncoding
, ZEND_ACC_PUBLIC
|ZEND_ACC_STATIC
)
793 PHP_ME(HttpEnv
, negotiateCharset
, ai_HttpEnv_negotiateCharset
, ZEND_ACC_PUBLIC
|ZEND_ACC_STATIC
)
794 PHP_ME(HttpEnv
, negotiate
, ai_HttpEnv_negotiate
, ZEND_ACC_PUBLIC
|ZEND_ACC_STATIC
)
799 zend_class_entry
*php_http_env_class_entry
;
801 PHP_MINIT_FUNCTION(http_env
)
803 zend_class_entry ce
= {0};
805 INIT_NS_CLASS_ENTRY(ce
, "http", "Env", php_http_env_methods
);
806 php_http_env_class_entry
= zend_register_internal_class(&ce TSRMLS_CC
);
817 * vim600: noet sw=4 ts=4 fdm=marker
818 * vim<600: noet sw=4 ts=4