X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=php_http_encoding_api.h;h=a87a8c6dfde985ae445e54408042970f1885b879;hp=7e235c7bc739cfabee25ebab86745d0261f69136;hb=e7e38363a2e833933519deb5f649d34fd7cc658d;hpb=e103c61ca14d22e9507379810e980075c8323ca3 diff --git a/php_http_encoding_api.h b/php_http_encoding_api.h index 7e235c7..a87a8c6 100644 --- a/php_http_encoding_api.h +++ b/php_http_encoding_api.h @@ -1,16 +1,13 @@ /* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ + +--------------------------------------------------------------------+ + | PECL :: http | + +--------------------------------------------------------------------+ + | Redistribution and use in source and binary forms, with or without | + | modification, are permitted provided that the conditions mentioned | + | in the accompanying LICENSE file are met. | + +--------------------------------------------------------------------+ + | Copyright (c) 2004-2005, Michael Wallner | + +--------------------------------------------------------------------+ */ /* $Id$ */ @@ -20,11 +17,53 @@ #include "php_http_std_defs.h" +#ifdef HTTP_HAVE_ZLIB +# include "phpstr/phpstr.h" +# include +#endif + #define http_encoding_dechunk(e, el, d, dl) _http_encoding_dechunk((e), (el), (d), (dl) TSRMLS_CC) PHP_HTTP_API const char *_http_encoding_dechunk(const char *encoded, size_t encoded_len, char **decoded, size_t *decoded_len TSRMLS_DC); +#define http_encoding_response_start(cl) _http_encoding_response_start((cl) TSRMLS_CC) +PHP_HTTP_API zend_bool _http_encoding_response_start(size_t content_length TSRMLS_DC); + #ifdef HTTP_HAVE_ZLIB +/* max count of uncompress trials, alloc_size <<= 2 for each try */ +#define HTTP_ENCODING_MAXTRY 10 +/* safe padding */ +#define HTTP_ENCODING_SAFPAD 10 +/* add 1% extra space in case we need to encode widely differing (binary) data */ +#define HTTP_ENCODING_BUFLEN(l) (l + (l / 100) + HTTP_ENCODING_SAFPAD) + +typedef enum { + HTTP_ENCODING_NONE = 0, + HTTP_ENCODING_ANY = 1, + HTTP_ENCODING_GZIP, + HTTP_ENCODING_DEFLATE, + HTTP_ENCODING_COMPRESS +} http_encoding_type; + +#define http_encode(t, l, d, dl, r, rl) _http_encode((t), (l), (d), (dl), (r), (rl) TSRMLS_CC) +PHP_HTTP_API STATUS _http_encode(http_encoding_type type, int level, const char *data, size_t data_len, char **encoded, size_t *encoded_len TSRMLS_DC); +#define http_decode(t, d, dl, r, rl) _http_decode((t), (l), (d), (dl), (r), (rl) TSRMLS_CC) +PHP_HTTP_API STATUS _http_decode(http_encoding_type type, const char *data, size_t data_len, char **decoded, size_t *decoded_len TSRMLS_DC); + +typedef struct { + z_stream Z; + int gzip; + ulong crc; + phpstr *storage; +} http_encoding_stream; + +#define http_encoding_stream_init(s, g, l, e, el) _http_encoding_stream_init((s), (g), (l), (e), (el) TSRMLS_CC) +PHP_HTTP_API STATUS _http_encoding_stream_init(http_encoding_stream *s, int gzip, int level, char **encoded, size_t *encoded_len TSRMLS_DC); +#define http_encoding_stream_update(s, d, dl, e, el) _http_encoding_stream_update((s), (d), (dl), (e), (el) TSRMLS_CC) +PHP_HTTP_API STATUS _http_encoding_stream_update(http_encoding_stream *s, const char *data, size_t data_len, char **encoded, size_t *encoded_len TSRMLS_DC); +#define http_encoding_stream_finish(s, e, el) _http_encoding_stream_finish((s), (e), (el) TSRMLS_CC) +PHP_HTTP_API STATUS _http_encoding_stream_finish(http_encoding_stream *s, char **encoded, size_t *encoded_len TSRMLS_DC); + #define http_encoding_gzencode(l, d, dl, r, rl) _http_encoding_gzencode((l), (d), (dl), (r), (rl) TSRMLS_CC) PHP_HTTP_API STATUS _http_encoding_gzencode(int level, const char *data, size_t data_len, char **encoded, size_t *encoded_len TSRMLS_DC); #define http_encoding_gzdecode(d, dl, r, rl) _http_encoding_gzdecode((d), (dl), (r), (rl) TSRMLS_CC)