- added missing HttpMessage::setBody()
[m6w6/ext-http] / php_http_message_api.h
index 507693f28ca70b5dbb77106f975dd8f322ff39e7..9ba60817e9161d1ad2acd0b70f6daaa4b0f331c6 100644 (file)
 
 /* $Id$ */
 
-/*
-DUMP:
-HttpMessage
-       ->toResponseString();
-       ->toRequestString();
-       ->__toString(); ->__sleep(); ->serialize();
-       ->fromString(); __wakeup($message); ->unserialize();
-       ->setStatusCode();
-       ->setHeader(); ->addHeader()...
-*/
+#ifndef PHP_HTTP_MESSAGE_API_H
+#define PHP_HTTP_MESSAGE_API_H
 
+#include "php_http_info_api.h"
 #include "phpstr/phpstr.h"
-#include "php_http_headers_api.h"
 
 typedef enum {
-       HTTP_MSG_NONE,
-       HTTP_MSG_REQUEST,
-       HTTP_MSG_RESPONSE
+       HTTP_MSG_NONE           = 0,
+       HTTP_MSG_REQUEST        = IS_HTTP_REQUEST,
+       HTTP_MSG_RESPONSE       = IS_HTTP_RESPONSE,
 } http_message_type;
 
 typedef struct _http_message http_message;
@@ -41,49 +33,61 @@ struct _http_message {
        phpstr body;
        HashTable hdrs;
        http_message_type type;
-
-       union {
-               struct {
-                       float http_version;
-                       char *method;
-                       char *URI;
-               } request;
-
-               struct {
-                       float http_version;
-                       int status;
-               } response;
-
-       } info;
-
-       size_t          len;
-       char            *raw;
-
-       http_message *nested;
+       struct http_info http;
+       http_message *parent;
 };
 
-/* required minimum length of an HTTP message "HTTP/1.1 200\r\n" */
-#define HTTP_MSG_MIN_SIZE 15
+/* required minimum length of an HTTP message "HTTP/1.1" */
+#define HTTP_MSG_MIN_SIZE 8
+
+/* shorthand for type checks */
+#define HTTP_MSG_TYPE(TYPE, msg) ((msg) && ((msg)->type == HTTP_MSG_ ##TYPE))
 
 #define http_message_new() _http_message_init_ex(NULL, 0)
 #define http_message_init(m) _http_message_init_ex((m), 0)
 #define http_message_init_ex(m, t) _http_message_init_ex((m), (t))
 PHP_HTTP_API http_message *_http_message_init_ex(http_message *m, http_message_type t);
 
-#define http_message_parse(m, l) http_message_parse_ex((m), (l), 1)
-#define http_message_parse_ex(m, l, d) _http_message_parse_ex((m), (l), (d) TSRMLS_CC)
-PHP_HTTP_API http_message *_http_message_parse_ex(char *message, size_t length, zend_bool duplicate TSRMLS_DC);
+#define http_message_set_type(m, t) _http_message_set_type((m), (t))
+PHP_HTTP_API void _http_message_set_type(http_message *m, http_message_type t);
 
-#define http_message_parse_headers_callback _http_message_parse_headers_callback
-PHP_HTTP_API void _http_message_parse_headers_callback(void *message, char *http_line, size_t line_length, HashTable **headers TSRMLS_DC);
+#define http_message_header(m, h) _http_message_header_ex((m), (h), sizeof(h))
+#define http_message_header_ex _http_message_header_ex
+static inline zval *_http_message_header_ex(http_message *msg, char *key_str, size_t key_len)
+{
+       zval **header;
+       if (SUCCESS == zend_hash_find(&msg->hdrs, key_str, key_len, (void **) &header)) {
+               return *header;
+       }
+       return NULL;
+}
+
+#define http_message_parse(m, l) http_message_parse_ex(NULL, (m), (l))
+#define http_message_parse_ex(h, m, l) _http_message_parse_ex((h), (m), (l) TSRMLS_CC)
+PHP_HTTP_API http_message *_http_message_parse_ex(http_message *msg, const char *message, size_t length TSRMLS_DC);
 
 #define http_message_tostring(m, s, l) _http_message_tostring((m), (s), (l))
 PHP_HTTP_API void _http_message_tostring(http_message *msg, char **string, size_t *length);
+
+#define http_message_serialize(m, s, l) _http_message_serialize((m), (s), (l))
+PHP_HTTP_API void _http_message_serialize(http_message *message, char **string, size_t *length);
+
+#define http_message_tostruct_recursive(m, s) _http_message_tostruct_recursive((m), (s) TSRMLS_CC)
+PHP_HTTP_API void _http_message_tostruct_recursive(http_message *msg, zval *strct TSRMLS_DC);
+
+#define http_message_send(m) _http_message_send((m) TSRMLS_CC)
+PHP_HTTP_API STATUS _http_message_send(http_message *message TSRMLS_DC);
+
+#define http_message_dup(m) _http_message_dup((m) TSRMLS_CC)
+PHP_HTTP_API http_message *_http_message_dup(http_message *msg TSRMLS_DC);
+
 #define http_message_dtor(m) _http_message_dtor((m))
 PHP_HTTP_API void _http_message_dtor(http_message *message);
 
 #define http_message_free(m) _http_message_free((m))
-PHP_HTTP_API void _http_message_free(http_message *message);
+PHP_HTTP_API void _http_message_free(http_message **message);
+
+#endif
 
 /*
  * Local variables: