commit lingering changes: http\Message::toStream() and ::toCallback()
authorMichael Wallner <mike@php.net>
Mon, 26 Mar 2012 15:49:02 +0000 (15:49 +0000)
committerMichael Wallner <mike@php.net>
Mon, 26 Mar 2012 15:49:02 +0000 (15:49 +0000)
php_http_message.c
php_http_message.h
php_http_message_body.c
php_http_misc.c
php_http_misc.h

index 176a27b56a2f489b288a4733725f700ae42b5841..b25f69741126b67d85ab6f167f63558432b8ba64 100644 (file)
@@ -606,6 +606,12 @@ PHP_HTTP_EMPTY_ARGS(__toString);
 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);
 
@@ -663,6 +669,8 @@ zend_function_entry php_http_message_method_entry[] = {
        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)
@@ -1692,6 +1700,46 @@ PHP_METHOD(HttpMessage, toString)
        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()) {
index f867d3704b2a341f770bf85d91f0e4c51c602263..81e1dd26a380fe742a5308adb6fb3193958f6d41 100644 (file)
@@ -118,7 +118,8 @@ PHP_METHOD(HttpMessage, guessContentType);
 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);
index 0374df3027088be4ee3feca88587e62c20ba8585..34741486fd908b9cf9f0675386c69b427285c961 100644 (file)
@@ -694,34 +694,10 @@ PHP_METHOD(HttpMessageBody, toStream)
        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)) {
@@ -731,7 +707,7 @@ PHP_METHOD(HttpMessageBody, toCallback)
                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);
index fa4bbbf2854add35e959331ea20fc48065acc843..c4661b7befc2988875ba6cacfbbbaf96cff83c96 100644 (file)
@@ -212,6 +212,22 @@ PHP_HTTP_API size_t php_http_pass_wrapper(php_http_pass_callback_arg_t *cb, cons
        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)
index 6c00cc50c98094c301863d0ca8dd9019a6722ac9..19ae6428de2665012c0fa295d5da681c72c51433 100644 (file)
@@ -418,6 +418,17 @@ typedef struct php_http_pass_callback_arg {
 
 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, ...);