PHP_HTTP_BEGIN_ARGS(toString, 0)
PHP_HTTP_ARG_VAL(include_parent, 0)
PHP_HTTP_END_ARGS;
+PHP_HTTP_BEGIN_ARGS(toCallback, 1)
+ PHP_HTTP_ARG_VAL(callback, 0)
+PHP_HTTP_END_ARGS;
+PHP_HTTP_BEGIN_ARGS(toStream, 1)
+ HTTP_ARG_VAL(stream, 0)
+PHP_HTTP_END_ARGS;
PHP_HTTP_EMPTY_ARGS(count);
PHP_HTTP_MESSAGE_ME(setHttpVersion, ZEND_ACC_PUBLIC)
PHP_HTTP_MESSAGE_ME(getParentMessage, ZEND_ACC_PUBLIC)
PHP_HTTP_MESSAGE_ME(toString, ZEND_ACC_PUBLIC)
+ PHP_HTTP_MESSAGE_ME(toCallback, ZEND_ACC_PUBLIC)
+ PHP_HTTP_MESSAGE_ME(toStream, ZEND_ACC_PUBLIC)
/* implements Countable */
PHP_HTTP_MESSAGE_ME(count, ZEND_ACC_PUBLIC)
RETURN_EMPTY_STRING();
}
+PHP_METHOD(HttpMessage, toStream)
+{
+ zval *zstream;
+
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zstream)) {
+ php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_stream *s;
+
+ php_stream_from_zval(s, &zstream);
+
+ if (!obj->message) {
+ obj->message = php_http_message_init(NULL, 0 TSRMLS_CC);
+ }
+
+ php_http_message_to_callback(obj->message, (php_http_pass_callback_t) _php_stream_write, s);
+ }
+}
+
+PHP_METHOD(HttpMessage, toCallback)
+{
+ zend_bool include_parent = 0;
+ php_http_pass_fcall_arg_t fcd;
+ long offset = 0, forlen = 0;
+
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f", &fcd.fci, &fcd.fcc)) {
+ php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ fcd.fcz = getThis();
+ Z_ADDREF_P(fcd.fcz);
+ TSRMLS_SET_CTX(fcd.ts);
+
+ php_http_message_to_callback(obj->message, php_http_pass_fcall_callback, &fcd);
+ zend_fcall_info_args_clear(&fcd.fci, 1);
+
+ zval_ptr_dtor(&fcd.fcz);
+ RETURN_TRUE;
+ }
+ RETURN_FALSE;
+}
+
PHP_METHOD(HttpMessage, serialize)
{
if (SUCCESS == zend_parse_parameters_none()) {
PHP_METHOD(HttpMessage, getParentMessage);
PHP_METHOD(HttpMessage, send);
PHP_METHOD(HttpMessage, toString);
-PHP_METHOD(HttpMessage, toMessageTypeObject);
+PHP_METHOD(HttpMessage, toStream);
+PHP_METHOD(HttpMessage, toCallback);
PHP_METHOD(HttpMessage, count);
PHP_METHOD(HttpMessage, serialize);
RETURN_FALSE;
}
-struct fcd {
- zval *fcz;
- zend_fcall_info fci;
- zend_fcall_info_cache fcc;
-#ifdef ZTS
- void ***ts;
-#endif
-};
-
-static size_t pass(void *cb_arg, const char *str, size_t len)
-{
- struct fcd *fcd = cb_arg;
- zval *zdata;
- TSRMLS_FETCH_FROM_CTX(fcd->ts);
-
- MAKE_STD_ZVAL(zdata);
- ZVAL_STRINGL(zdata, str, len, 1);
- if (SUCCESS == zend_fcall_info_argn(&fcd->fci TSRMLS_CC, 2, &fcd->fcz, &zdata)) {
- zend_fcall_info_call(&fcd->fci, &fcd->fcc, NULL, NULL TSRMLS_CC);
- zend_fcall_info_args_clear(&fcd->fci, 0);
- }
- zval_ptr_dtor(&zdata);
- return len;
-}
PHP_METHOD(HttpMessageBody, toCallback)
{
- struct fcd fcd;
+ php_http_pass_fcall_arg_t fcd;
long offset = 0, forlen = 0;
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f|ll", &fcd.fci, &fcd.fcc, &offset, &forlen)) {
Z_ADDREF_P(fcd.fcz);
TSRMLS_SET_CTX(fcd.ts);
- php_http_message_body_to_callback(obj->body, pass, &fcd, offset, forlen);
+ php_http_message_body_to_callback(obj->body, php_http_pass_fcall_callback, &fcd, offset, forlen);
zend_fcall_info_args_clear(&fcd.fci, 1);
zval_ptr_dtor(&fcd.fcz);
return cb->cb_zts(cb->cb_arg, str, len TSRMLS_CC);
}
+PHP_HTTP_API size_t php_http_pass_fcall_callback(void *cb_arg, const char *str, size_t len)
+{
+ php_http_pass_fcall_arg_t *fcd = cb_arg;
+ zval *zdata;
+ TSRMLS_FETCH_FROM_CTX(fcd->ts);
+
+ MAKE_STD_ZVAL(zdata);
+ ZVAL_STRINGL(zdata, str, len, 1);
+ if (SUCCESS == zend_fcall_info_argn(&fcd->fci TSRMLS_CC, 2, &fcd->fcz, &zdata)) {
+ zend_fcall_info_call(&fcd->fci, &fcd->fcc, NULL, NULL TSRMLS_CC);
+ zend_fcall_info_args_clear(&fcd->fci, 0);
+ }
+ zval_ptr_dtor(&zdata);
+ return len;
+}
+
/* ERROR */
static inline int scope_error_handling(long type TSRMLS_DC)
PHP_HTTP_API size_t php_http_pass_wrapper(php_http_pass_callback_arg_t *cb_arg, const char *str, size_t len);
+typedef struct php_http_pass_fcall_arg {
+ zval *fcz;
+ zend_fcall_info fci;
+ zend_fcall_info_cache fcc;
+#ifdef ZTS
+ void ***ts;
+#endif
+} php_http_pass_fcall_arg_t;
+
+PHP_HTTP_API size_t php_http_pass_fcall_callback(void *cb_arg, const char *str, size_t len);
+
/* ERROR */
extern void php_http_error(long type TSRMLS_DC, long code, const char *format, ...);