+/* {{{ proto string http_put_stream(string url, resource stream[, array options[, array &info]])
+ *
+ * Performs an HTTP PUT request, uploading stream.
+ * Returns the HTTP response as string.
+ * See http_get() for a full list of available options.
+ */
+PHP_FUNCTION(http_put_stream)
+{
+ zval *resource, *options = NULL, *info = NULL;
+ char *URL;
+ int URL_len;
+ phpstr response;
+ php_stream *stream;
+ php_stream_statbuf ssb;
+ http_request_body body;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sr|a/!z", &URL, &URL_len, &resource, &options, &info)) {
+ RETURN_FALSE;
+ }
+
+ php_stream_from_zval(stream, &resource);
+ if (php_stream_stat(stream, &ssb)) {
+ RETURN_FALSE;
+ }
+
+ if (info) {
+ zval_dtor(info);
+ array_init(info);
+ }
+
+ body.type = HTTP_REQUEST_BODY_UPLOADFILE;
+ body.data = stream;
+ body.size = ssb.sb.st_size;
+
+ phpstr_init_ex(&response, HTTP_CURLBUF_SIZE, 0);
+ if (SUCCESS == http_put(URL, &body, options ? Z_ARRVAL_P(options) : NULL, info ? Z_ARRVAL_P(info) : NULL, &response)) {
+ RETURN_PHPSTR_VAL(response);
+ } else {
+ RETURN_NULL();
+ }
+}
+/* }}} */
+
+/* {{{ proto long http_request_method_register(string method)
+ *
+ * Register a custom request method.
+ */
+PHP_FUNCTION(http_request_method_register)
+{
+ char *method;
+ int *method_len;
+ unsigned long existing;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &method, &method_len)) {
+ RETURN_FALSE;
+ }
+ if (existing = http_request_method_exists(1, 0, method)) {
+ RETURN_LONG((long) existing);
+ }
+
+ RETVAL_LONG((long) http_request_method_register(method));
+}
+/* }}} */
+
+/* {{{ proto bool http_request_method_unregister(mixed method)
+ *
+ * Unregister a previously registered custom request method.
+ */
+PHP_FUNCTION(http_request_method_unregister)
+{
+ zval *method;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/", &method)) {
+ RETURN_FALSE;
+ }
+
+ switch (Z_TYPE_P(method))
+ {
+ case IS_OBJECT:
+ convert_to_string(method);
+ case IS_STRING:
+#include "zend_operators.h"
+ if (is_numeric_string(Z_STRVAL_P(method), Z_STRLEN_P(method), NULL, NULL, 1)) {
+ convert_to_long(method);
+ } else {
+ unsigned long mn;
+ if (!(mn = http_request_method_exists(1, 0, Z_STRVAL_P(method)))) {
+ RETURN_FALSE;
+ }
+ zval_dtor(method);
+ ZVAL_LONG(method, (long)mn);
+ }
+ case IS_LONG:
+ RETURN_SUCCESS(http_request_method_unregister(Z_LVAL_P(method)));
+ default:
+ RETURN_FALSE;
+ }
+}
+/* }}} */
+
+/* {{{ proto long http_request_method_exists(mixed method)
+ *
+ * Check if a request method is registered (or available by default).
+ */
+PHP_FUNCTION(http_request_method_exists)
+{
+ IF_RETVAL_USED {
+ zval *method;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/", &method)) {
+ RETURN_FALSE;
+ }
+
+ switch (Z_TYPE_P(method))
+ {
+ case IS_OBJECT:
+ convert_to_string(method);
+ case IS_STRING:
+ if (is_numeric_string(Z_STRVAL_P(method), Z_STRLEN_P(method), NULL, NULL, 1)) {
+ convert_to_long(method);
+ } else {
+ RETURN_LONG((long) http_request_method_exists(1, 0, Z_STRVAL_P(method)));
+ }
+ case IS_LONG:
+ RETURN_LONG((long) http_request_method_exists(0, Z_LVAL_P(method), NULL));
+ default:
+ RETURN_FALSE;
+ }
+ }
+}
+/* }}} */
+
+/* {{{ proto string http_request_method_name(long method)
+ *
+ * Get the literal string representation of a standard or registered request method.
+ */
+PHP_FUNCTION(http_request_method_name)
+{
+ IF_RETVAL_USED {
+ long method;
+
+ if ((SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &method)) || (method < 0)) {
+ RETURN_FALSE;
+ }
+
+ RETURN_STRING(estrdup(http_request_method_name((unsigned long) method)), 0);
+ }
+}
+/* }}} */