9147cbfde4e8aa3bac826e6b7ddda3937dbee135
[m6w6/ext-http] / php_http_message_body.h
1 /*
2 +--------------------------------------------------------------------+
3 | PECL :: http |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2004-2011, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
11 */
12
13 #ifndef PHP_HTTP_MESSAGE_BODY_H
14 #define PHP_HTTP_MESSAGE_BODY_H
15
16 typedef struct php_http_message_body {
17 int stream_id;
18 php_stream_statbuf ssb;
19 char *boundary;
20 #ifdef ZTS
21 void ***ts;
22 #endif
23 } php_http_message_body_t;
24
25 PHP_HTTP_API php_http_message_body_t *php_http_message_body_init(php_http_message_body_t *body, php_stream *stream TSRMLS_DC);
26 PHP_HTTP_API php_http_message_body_t *php_http_message_body_copy(php_http_message_body_t *from, php_http_message_body_t *to, zend_bool dup_internal_stream_and_contents);
27 PHP_HTTP_API STATUS php_http_message_body_add(php_http_message_body_t *body, HashTable *fields, HashTable *files);
28 PHP_HTTP_API STATUS php_http_message_body_add_field(php_http_message_body_t *body, const char *name, const char *value_str, size_t value_len);
29 PHP_HTTP_API STATUS php_http_message_body_add_file(php_http_message_body_t *body, const char *name, const char *path, const char *ctype);
30 PHP_HTTP_API size_t php_http_message_body_append(php_http_message_body_t *body, const char *buf, size_t len);
31 PHP_HTTP_API void php_http_message_body_to_string(php_http_message_body_t *body, char **buf, size_t *len, off_t offset, size_t forlen);
32 PHP_HTTP_API void php_http_message_body_to_stream(php_http_message_body_t *body, php_stream *s, off_t offset, size_t forlen);
33 PHP_HTTP_API void php_http_message_body_to_callback(php_http_message_body_t *body, php_http_pass_callback_t cb, void *cb_arg, off_t offset, size_t forlen);
34 PHP_HTTP_API void php_http_message_body_dtor(php_http_message_body_t *body);
35 PHP_HTTP_API void php_http_message_body_free(php_http_message_body_t **body);
36 PHP_HTTP_API const php_stream_statbuf *php_http_message_body_stat(php_http_message_body_t *body);
37 #define php_http_message_body_size(b) (php_http_message_body_stat((b))->sb.st_size)
38 #define php_http_message_body_mtime(b) (php_http_message_body_stat((b))->sb.st_mtime)
39 PHP_HTTP_API char *php_http_message_body_etag(php_http_message_body_t *body);
40 PHP_HTTP_API const char *php_http_message_body_boundary(php_http_message_body_t *body);
41
42 static inline php_stream *php_http_message_body_stream(php_http_message_body_t *body)
43 {
44 TSRMLS_FETCH_FROM_CTX(body->ts);
45 return zend_fetch_resource(NULL TSRMLS_CC, body->stream_id, "stream", NULL, 2, php_file_le_stream(), php_file_le_pstream());
46 }
47
48
49 typedef struct php_http_message_body_object {
50 zend_object zo;
51 php_http_message_body_t *body;
52 } php_http_message_body_object_t;
53
54 extern zend_class_entry *php_http_message_body_class_entry;
55 extern zend_function_entry php_http_message_body_method_entry[];
56
57 extern PHP_MINIT_FUNCTION(http_message_body);
58
59 extern zend_object_value php_http_message_body_object_new(zend_class_entry *ce TSRMLS_DC);
60 extern zend_object_value php_http_message_body_object_new_ex(zend_class_entry *ce, php_http_message_body_t *body, php_http_message_body_object_t **ptr TSRMLS_DC);
61 extern zend_object_value php_http_message_body_object_clone(zval *object TSRMLS_DC);
62 extern void php_http_message_body_object_free(void *object TSRMLS_DC);
63
64 PHP_METHOD(HttpMessageBody, __construct);
65 PHP_METHOD(HttpMessageBody, __toString);
66 PHP_METHOD(HttpMessageBody, toStream);
67 PHP_METHOD(HttpMessageBody, toCallback);
68 PHP_METHOD(HttpMessageBody, append);
69 PHP_METHOD(HttpMessageBody, add);
70 PHP_METHOD(HttpMessageBody, etag);
71 PHP_METHOD(HttpMessageBody, stat);
72
73 #endif
74
75 /*
76 * Local variables:
77 * tab-width: 4
78 * c-basic-offset: 4
79 * End:
80 * vim600: noet sw=4 ts=4 fdm=marker
81 * vim<600: noet sw=4 ts=4
82 */
83