#endif /* !ZEND_ENGINE_2 */
/* }}} */
+/* {{{ */
+#ifdef HTTP_HAVE_ZLIB
+
+/* {{{ proto string http_gzencode(string data[, int level = -1])
+ *
+ * Compress data with the HTTP compatible GZIP encoding.
+ *
+ * Expects the first parameter to be a string which contains the data that
+ * should be encoded. Additionally accepts an optional in paramter specifying
+ * the compression level, where -1 is default, 0 is no compression and 9 is
+ * best compression ratio.
+ *
+ * Returns the encoded string on success, or NULL on failure.
+ */
+PHP_FUNCTION(http_gzencode)
+{
+ char *data;
+ int data_len;
+ long level = -1;
+
+ RETVAL_NULL();
+
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &data, &data_len, &level)) {
+ HTTP_CHECK_GZIP_LEVEL(level, return);
+ {
+ char *encoded;
+ size_t encoded_len;
+
+ if (SUCCESS == http_encoding_gzencode(level, data, data_len, &encoded, &encoded_len)) {
+ RETURN_STRINGL(encoded, (int) encoded_len, 0);
+ }
+ }
+ }
+}
+/* }}} */
+
+/* {{{ proto string http_gzdecode(string data)
+ *
+ * Uncompress data compressed with the HTTP compatible GZIP encoding.
+ *
+ * Expects a string as parameter containing the compressed data.
+ *
+ * Returns the decoded string on success, or NULL on failure.
+ */
+PHP_FUNCTION(http_gzdecode)
+{
+ char *data;
+ int data_len;
+
+ RETVAL_NULL();
+
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &data, &data_len)) {
+ char *decoded;
+ size_t decoded_len;
+
+ if (SUCCESS == http_encoding_gzdecode(data, data_len, &decoded, &decoded_len)) {
+ RETURN_STRINGL(decoded, (int) decoded_len, 0);
+ }
+ }
+}
+/* }}} */
+
+/* {{{ proto string http_deflate(string data[, int level = -1])
+ *
+ * Compress data with the HTTP compatible DEFLATE encoding.
+ *
+ * Expects the first parameter to be a string containing the data that should
+ * be encoded. Additionally accepts an optional int parameter specifying the
+ * compression level, where -1 is default, 0 is no compression and 9 is best
+ * compression ratio.
+ *
+ * Returns the encoded string on success, or NULL on failure.
+ */
+PHP_FUNCTION(http_deflate)
+{
+ char *data;
+ int data_len;
+ long level = -1;
+
+ RETVAL_NULL();
+
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &data, &data_len, &level)) {
+ HTTP_CHECK_GZIP_LEVEL(level, return);
+ {
+ char *encoded;
+ size_t encoded_len;
+
+ if (SUCCESS == http_encoding_deflate(level, data, data_len, &encoded, &encoded_len)) {
+ RETURN_STRINGL(encoded, (int) encoded_len, 0);
+ }
+ }
+ }
+}
+/* }}} */
+
+/* {{{ proto string http_inflate(string data)
+ *
+ * Uncompress data compressed with the HTTP compatible DEFLATE encoding.
+ *
+ * Expects a string as parameter containing the compressed data.
+ *
+ * Returns the decoded string on success, or NULL on failure.
+ */
+PHP_FUNCTION(http_inflate)
+{
+ char *data;
+ int data_len;
+
+ RETVAL_NULL();
+
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &data, &data_len)) {
+ char *decoded;
+ size_t decoded_len;
+
+ if (SUCCESS == http_encoding_inflate(data, data_len, &decoded, &decoded_len)) {
+ RETURN_STRINGL(decoded, (int) decoded_len, 0);
+ }
+ }
+}
+/* }}} */
+
+/* {{{ proto string http_compress(string data[, int level = -1])
+ *
+ * Compress data with the HTTP compatible COMPRESS encoding.
+ *
+ * Expects the first parameter to be a string containing the data which should
+ * be encoded. Additionally accepts an optional int parameter specifying the
+ * compression level, where -1 is default, 0 is no compression and 9 is best
+ * compression ratio.
+ *
+ * Returns the encoded string on success, or NULL on failure.
+ */
+PHP_FUNCTION(http_compress)
+{
+ char *data;
+ int data_len;
+ long level;
+
+ RETVAL_NULL();
+
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &data, &data_len, &level)) {
+ HTTP_CHECK_GZIP_LEVEL(level, return);
+ {
+ char *encoded;
+ size_t encoded_len;
+
+ if (SUCCESS == http_encoding_compress(level, data, data_len, &encoded, &encoded_len)) {
+ RETURN_STRINGL(encoded, (int) encoded_len, 0);
+ }
+ }
+ }
+}
+/* }}} */
+
+/* {{{ proto string http_uncompress(string data)
+ *
+ * Uncompress data compressed with the HTTP compatible COMPRESS encoding.
+ *
+ * Expects a string as parameter containing the compressed data.
+ *
+ * Returns the decoded string on success, or NULL on failure.
+ */
+PHP_FUNCTION(http_uncompress)
+{
+ char *data;
+ int data_len;
+
+ RETVAL_NULL();
+
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &data, &data_len)) {
+ char *decoded;
+ size_t decoded_len;
+
+ if (SUCCESS == http_encoding_uncompress(data, data_len, &decoded, &decoded_len)) {
+ RETURN_STRINGL(decoded, decoded_len, 0);
+ }
+ }
+}
+/* }}} */
+#endif /* HTTP_HAVE_ZLIB */
+/* }}} */
+
PHP_FUNCTION(http_test)
{
}
HTTP_ARG_VAL(case_sensitive, 0)
HTTP_END_ARGS;
-HTTP_BEGIN_ARGS(chunkedDecode, 1)
- HTTP_ARG_VAL(encoded_string, 0)
-HTTP_END_ARGS;
-
HTTP_BEGIN_ARGS(parseMessage, 1)
HTTP_ARG_VAL(message_string, 0)
HTTP_END_ARGS;
HTTP_ARG_VAL(headers_string, 0)
HTTP_END_ARGS;
+HTTP_BEGIN_ARGS(chunkedDecode, 1)
+ HTTP_ARG_VAL(encoded_string, 0)
+HTTP_END_ARGS;
+
+HTTP_BEGIN_ARGS(gzEncode, 1)
+ HTTP_ARG_VAL(plain, 0)
+ HTTP_ARG_VAL(level, 0)
+HTTP_END_ARGS;
+
+HTTP_BEGIN_ARGS(gzDecode, 1)
+ HTTP_ARG_VAL(encoded, 0)
+HTTP_END_ARGS;
+
+HTTP_BEGIN_ARGS(deflate, 1)
+ HTTP_ARG_VAL(plain, 0)
+ HTTP_ARG_VAL(level, 0)
+HTTP_END_ARGS;
+
+HTTP_BEGIN_ARGS(inflate, 1)
+ HTTP_ARG_VAL(encoded, 0)
+HTTP_END_ARGS;
+
+HTTP_BEGIN_ARGS(compress, 1)
+ HTTP_ARG_VAL(plain, 0)
+ HTTP_ARG_VAL(level, 0)
+HTTP_END_ARGS;
+
+HTTP_BEGIN_ARGS(uncompress, 1)
+ HTTP_ARG_VAL(encoded, 0)
+HTTP_END_ARGS;
+
zend_class_entry *http_util_object_ce;
zend_function_entry http_util_object_fe[] = {
HTTP_UTIL_ALIAS(date, http_date)
HTTP_UTIL_ALIAS(matchModified, http_match_modified)
HTTP_UTIL_ALIAS(matchEtag, http_match_etag)
HTTP_UTIL_ALIAS(matchRequestHeader, http_match_request_header)
- HTTP_UTIL_ALIAS(chunkedDecode, http_chunked_decode)
HTTP_UTIL_ALIAS(parseMessage, http_parse_message)
HTTP_UTIL_ALIAS(parseHeaders, http_parse_headers)
+ HTTP_UTIL_ALIAS(chunkedDecode, http_chunked_decode)
+ HTTP_UTIL_ALIAS(gzEncode, http_gzencode)
+ HTTP_UTIL_ALIAS(gzDecode, http_gzdecode)
+ HTTP_UTIL_ALIAS(deflate, http_deflate)
+ HTTP_UTIL_ALIAS(inflate, http_inflate)
+ HTTP_UTIL_ALIAS(compress, http_compress)
+ HTTP_UTIL_ALIAS(uncompress, http_uncompress)
EMPTY_FUNCTION_ENTRY
};
<notes><![CDATA[
+ Updated documentation (a lot)
+ Added optional third parameter to HttpRequest::__construct() accepting an array with options
++ Added compression functions gzencode/gzdecode, deflate/inflate, compress/uncompress
- Renamed http_absolute_uri() to http_build_uri() (complements with http_build_query())
- Changed the signature of the negotiator to fill the second parameter with the results array
<file role="src" name="php_http_api.h"/>
<file role="src" name="php_http_cache_api.h"/>
<file role="src" name="php_http_date_api.h"/>
+ <file role="src" name="php_http_encoding_api.h">
<file role="src" name="php_http_headers_api.h"/>
<file role="src" name="php_http_info_api.h"/>
<file role="src" name="php_http_message_api.h"/>
<file role="src" name="http_api.c"/>
<file role="src" name="http_cache_api.c"/>
<file role="src" name="http_date_api.c"/>
+ <file role="src" name="http_encoding_api.c">
<file role="src" name="http_headers_api.c"/>
<file role="src" name="http_info_api.c"/>
<file role="src" name="http_message_api.c"/>
PHP_FUNCTION(http_build_query);
#endif /* ZEND_ENGINE_2 */
PHP_FUNCTION(ob_etaghandler);
+#ifdef HTTP_HAVE_ZLIB
+PHP_FUNCTION(http_gzencode);
+PHP_FUNCTION(http_gzdecode);
+PHP_FUNCTION(http_deflate);
+PHP_FUNCTION(http_inflate);
+PHP_FUNCTION(http_compress);
+PHP_FUNCTION(http_uncompress);
+#endif
PHP_MINIT_FUNCTION(http);
PHP_MSHUTDOWN_FUNCTION(http);
http_error(HE_NOTICE, HTTP_E_MESSAGE_TYPE, "HttpMessage is not of type HTTP_MSG_REQUEST"); \
action; \
}
-
+#define HTTP_CHECK_GZIP_LEVEL(level, action) \
+ if (level < -1 || level > 9) { \
+ http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Invalid compression level (-1 to 9): %d", level); \
+ action; \
+ }
#define http_log(f, i, m) _http_log_ex((f), (i), (m) TSRMLS_CC)
extern void http_log_ex(char *file, const char *ident, const char *message TSRMLS_DC);
PHP_METHOD(HttpUtil, negotiateCharset);
PHP_METHOD(HttpUtil, matchModified);
PHP_METHOD(HttpUtil, matchEtag);
-PHP_METHOD(HttpUtil, chunkedDecode);
PHP_METHOD(HttpUtil, parseHeaders);
PHP_METHOD(HttpUtil, parseMessage);
+PHP_METHOD(HttpUtil, chunkedDecode);
+PHP_METHOD(HttpUtil, gzEncode);
+PHP_METHOD(HttpUtil, gzDecode);
+PHP_METHOD(HttpUtil, deflate);
+PHP_METHOD(HttpUtil, inflate);
+PHP_METHOD(HttpUtil, compress);
+PHP_METHOD(HttpUtil, uncompress);
#endif
#endif
"
["parentMessage"]=>
NULL
-}Done
+}
+Done
+