X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=php_http_buffer.h;h=faf8992107675be7b39f744fc0ae069f9326a410;hp=ee78c41165f048ea5bd4b505c3dd141401dc4f7c;hb=791511f3bc18cdc68b3f27b43d9396cf56d99e5a;hpb=b7d38027432247956b62e12f2c56ac3fffb77318 diff --git a/php_http_buffer.h b/php_http_buffer.h index ee78c41..faf8992 100644 --- a/php_http_buffer.h +++ b/php_http_buffer.h @@ -1,8 +1,17 @@ +/* + +--------------------------------------------------------------------+ + | 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-2014, Michael Wallner | + +--------------------------------------------------------------------+ +*/ -/* $Id: php_http_buffer_t.h 229282 2007-02-07 15:31:50Z mike $ */ - -#ifndef _PHP_HTTP_BUFFER_H -#define _PHP_HTTP_BUFFER_H +#ifndef PHP_HTTP_BUFFER_H +#define PHP_HTTP_BUFFER_H #ifndef PHP_HTTP_BUFFER_DEFAULT_SIZE # define PHP_HTTP_BUFFER_DEFAULT_SIZE 256 @@ -12,19 +21,19 @@ #define PHP_HTTP_BUFFER_NOMEM PHP_HTTP_BUFFER_ERROR #define PHP_HTTP_BUFFER_PASS0 PHP_HTTP_BUFFER_ERROR -#ifndef STR_FREE -# define STR_FREE(STR) \ +#ifndef PTR_FREE +# define PTR_FREE(PTR) \ { \ - if (STR) { \ - efree(STR); \ + if (PTR) { \ + efree(PTR); \ } \ } #endif -#ifndef STR_SET -# define STR_SET(STR, SET) \ +#ifndef PTR_SET +# define PTR_SET(PTR, SET) \ { \ - STR_FREE(STR); \ - STR = SET; \ + PTR_FREE(PTR); \ + PTR = SET; \ } #endif #ifndef TSRMLS_D @@ -65,8 +74,6 @@ static inline void *estrndup(void *p, size_t s) #endif #define PHP_HTTP_BUFFER(p) ((php_http_buffer_t *) (p)) -#define PHP_HTTP_BUFFER_VAL(p) (PHP_HTTP_BUFFER(p))->data -#define PHP_HTTP_BUFFER_LEN(p) (PHP_HTTP_BUFFER(p))->used #define FREE_PHP_HTTP_BUFFER_PTR(STR) pefree(STR, STR->pmem) #define FREE_PHP_HTTP_BUFFER_VAL(STR) php_http_buffer_dtor(STR) @@ -74,16 +81,21 @@ static inline void *estrndup(void *p, size_t s) #define FREE_PHP_HTTP_BUFFER(free, STR) \ switch (free) \ { \ - case PHP_HTTP_BUFFER_FREE_NOT: break; \ - case PHP_HTTP_BUFFER_FREE_PTR: pefree(STR, STR->pmem); break; \ - case PHP_HTTP_BUFFER_FREE_VAL: php_http_buffer_dtor(STR); break; \ - case PHP_HTTP_BUFFER_FREE_ALL: \ - { \ - php_http_buffer_t *PTR = (STR); \ - php_http_buffer_free(&PTR); \ - } \ + case PHP_HTTP_BUFFER_FREE_NOT: \ + break; \ + case PHP_HTTP_BUFFER_FREE_PTR: \ + pefree(STR, STR->pmem); break; \ + break; \ + case PHP_HTTP_BUFFER_FREE_VAL: \ + php_http_buffer_dtor(STR); \ + break; \ + case PHP_HTTP_BUFFER_FREE_ALL: { \ + php_http_buffer_t *PTR = (STR); \ + php_http_buffer_free(&PTR); \ + break; \ + } \ + default:\ break; \ - default: break; \ } #define RETURN_PHP_HTTP_BUFFER_PTR(STR) RETURN_PHP_HTTP_BUFFER((STR), PHP_HTTP_BUFFER_FREE_PTR, 0) @@ -142,6 +154,8 @@ PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_from_string_ex(php_http_b #define php_http_buffer_resize(b, s) php_http_buffer_resize_ex((b), (s), 0, 0) PHP_HTTP_BUFFER_API size_t php_http_buffer_resize_ex(php_http_buffer_t *buf, size_t len, size_t override_size, int allow_error); +PHP_HTTP_BUFFER_API char *php_http_buffer_account(php_http_buffer_t *buf, size_t to_account); + /* shrink memory chunk to actually used size (+1) */ PHP_HTTP_BUFFER_API size_t php_http_buffer_shrink(php_http_buffer_t *buf); @@ -151,51 +165,15 @@ PHP_HTTP_BUFFER_API size_t php_http_buffer_shrink(php_http_buffer_t *buf); PHP_HTTP_BUFFER_API size_t php_http_buffer_append(php_http_buffer_t *buf, const char *append, size_t append_len); PHP_HTTP_BUFFER_API size_t php_http_buffer_appendf(php_http_buffer_t *buf, const char *format, ...) PHP_HTTP_BUFFER_ATTRIBUTE_FORMAT(printf, 2, 3); -/* insert data at a specific position of the php_http_buffer_t */ -#define php_http_buffer_inserts(b, i, o) php_http_buffer_insert((b), (i), sizeof(i)-1, (o)) -#define php_http_buffer_insertl(b, i, o) php_http_buffer_insert((b), (i), strlen(i), (o)) -PHP_HTTP_BUFFER_API size_t php_http_buffer_insert(php_http_buffer_t *buf, const char *insert, size_t insert_len, size_t offset); -PHP_HTTP_BUFFER_API size_t php_http_buffer_insertf(php_http_buffer_t *buf, size_t offset, const char *format, ...) PHP_HTTP_BUFFER_ATTRIBUTE_FORMAT(printf, 3, 4); - -/* prepend data */ -#define php_http_buffer_prepends(b, p) php_http_buffer_prepend((b), (p), sizeof(p)-1) -#define php_http_buffer_prependl(b, p) php_http_buffer_prepend((b), (p), strlen(p)) -PHP_HTTP_BUFFER_API size_t php_http_buffer_prepend(php_http_buffer_t *buf, const char *prepend, size_t prepend_len); -PHP_HTTP_BUFFER_API size_t php_http_buffer_prependf(php_http_buffer_t *buf, const char *format, ...) PHP_HTTP_BUFFER_ATTRIBUTE_FORMAT(printf, 2, 3); - /* get a zero-terminated string */ PHP_HTTP_BUFFER_API char *php_http_buffer_data(const php_http_buffer_t *buf, char **into, size_t *len); -/* get a part of the php_http_buffer_t */ -#define php_http_buffer_mid(b, o, l) php_http_buffer_sub((b), (o), (l)) -#define php_http_buffer_left(b, l) php_http_buffer_sub((b), 0, (l)) -PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_right(const php_http_buffer_t *buf, size_t length); -PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_sub(const php_http_buffer_t *buf, size_t offset, size_t len); - /* remove a substring */ PHP_HTTP_BUFFER_API size_t php_http_buffer_cut(php_http_buffer_t *buf, size_t offset, size_t length); -/* get a complete php_http_buffer_t duplicate */ -PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_copy(const php_http_buffer_t *from, php_http_buffer_t *to); - -/* merge several php_http_buffer_t objects - use like: - - php_http_buffer_t *final = php_http_buffer_merge(3, - PHP_HTTP_BUFFER_NOT_FREE(&keep), - PHP_HTTP_BUFFER_ALL_FREE(middle_ptr), - PHP_HTTP_BUFFER_VAL_FREE(&local); -*/ -PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_merge(unsigned argc, ...); -PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_merge_ex(php_http_buffer_t *buf, unsigned argc, ...); -PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_merge_va(php_http_buffer_t *buf, unsigned argc, va_list argv); - /* sets a trailing NUL byte */ PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_fix(php_http_buffer_t *buf); -/* memcmp for php_http_buffer_t objects */ -PHP_HTTP_BUFFER_API int php_http_buffer_cmp(php_http_buffer_t *left, php_http_buffer_t *right); - /* reset php_http_buffer_t object */ PHP_HTTP_BUFFER_API void php_http_buffer_reset(php_http_buffer_t *buf); @@ -208,15 +186,58 @@ PHP_HTTP_BUFFER_API void php_http_buffer_free(php_http_buffer_t **buf); /* stores data in a php_http_buffer_t until it reaches chunk_size */ PHP_HTTP_BUFFER_API size_t php_http_buffer_chunk_buffer(php_http_buffer_t **s, const char *data, size_t data_len, char **chunk, size_t chunk_size); -typedef size_t (*php_http_buffer_pass_func_t)(void *opaque, const char *, size_t TSRMLS_DC); +typedef size_t (*php_http_buffer_pass_func_t)(void *opaque, char *, size_t TSRMLS_DC); + +PHP_HTTP_BUFFER_API ssize_t php_http_buffer_passthru(php_http_buffer_t **s, size_t chunk_size, php_http_buffer_pass_func_t passin, void *passin_arg, php_http_buffer_pass_func_t passon, void *passon_arg TSRMLS_DC); /* wrapper around php_http_buffer_chunk_buffer, which passes available chunks to passthru() */ -PHP_HTTP_BUFFER_API void php_http_buffer_chunked_output(php_http_buffer_t **s, const char *data, size_t data_len, size_t chunk_size, php_http_buffer_pass_func_t passout, void *opaque TSRMLS_DC); +PHP_HTTP_BUFFER_API size_t php_http_buffer_chunked_output(php_http_buffer_t **s, const char *data, size_t data_len, size_t chunk_size, php_http_buffer_pass_func_t passout, void *opaque TSRMLS_DC); /* write chunks directly into php_http_buffer_t buffer */ PHP_HTTP_BUFFER_API size_t php_http_buffer_chunked_input(php_http_buffer_t **s, size_t chunk_size, php_http_buffer_pass_func_t passin, void *opaque TSRMLS_DC); -#endif + +# ifdef PHP_HTTP_BUFFER_EXTENDED + +/* memcmp for php_http_buffer_t objects */ +PHP_HTTP_BUFFER_API int php_http_buffer_cmp(php_http_buffer_t *left, php_http_buffer_t *right); + +/* get a complete php_http_buffer_t duplicate */ +PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_copy(const php_http_buffer_t *from, php_http_buffer_t *to); + +/* merge several php_http_buffer_t objects + use like: + + php_http_buffer_t *final = php_http_buffer_merge(3, + PHP_HTTP_BUFFER_NOT_FREE(&keep), + PHP_HTTP_BUFFER_ALL_FREE(middle_ptr), + PHP_HTTP_BUFFER_VAL_FREE(&local); +*/ +PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_merge(unsigned argc, ...); +PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_merge_ex(php_http_buffer_t *buf, unsigned argc, ...); +PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_merge_va(php_http_buffer_t *buf, unsigned argc, va_list argv); + +/* insert data at a specific position of the php_http_buffer_t */ +#define php_http_buffer_inserts(b, i, o) php_http_buffer_insert((b), (i), sizeof(i)-1, (o)) +#define php_http_buffer_insertl(b, i, o) php_http_buffer_insert((b), (i), strlen(i), (o)) +PHP_HTTP_BUFFER_API size_t php_http_buffer_insert(php_http_buffer_t *buf, const char *insert, size_t insert_len, size_t offset); +PHP_HTTP_BUFFER_API size_t php_http_buffer_insertf(php_http_buffer_t *buf, size_t offset, const char *format, ...) PHP_HTTP_BUFFER_ATTRIBUTE_FORMAT(printf, 3, 4); + +/* prepend data */ +#define php_http_buffer_prepends(b, p) php_http_buffer_prepend((b), (p), sizeof(p)-1) +#define php_http_buffer_prependl(b, p) php_http_buffer_prepend((b), (p), strlen(p)) +PHP_HTTP_BUFFER_API size_t php_http_buffer_prepend(php_http_buffer_t *buf, const char *prepend, size_t prepend_len); +PHP_HTTP_BUFFER_API size_t php_http_buffer_prependf(php_http_buffer_t *buf, const char *format, ...) PHP_HTTP_BUFFER_ATTRIBUTE_FORMAT(printf, 2, 3); + +/* get a part of the php_http_buffer_t */ +#define php_http_buffer_mid(b, o, l) php_http_buffer_sub((b), (o), (l)) +#define php_http_buffer_left(b, l) php_http_buffer_sub((b), 0, (l)) +PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_right(const php_http_buffer_t *buf, size_t length); +PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_sub(const php_http_buffer_t *buf, size_t offset, size_t len); + +# endif /* PHP_HTTP_BUFFER_EXTENDED */ + +#endif /* PHP_HTTP_BUFFER_H */ /*