release 2.4.2
[m6w6/ext-http] / php_http_info.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-2014, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
11 */
12
13 #ifndef PHP_HTTP_INFO_H
14 #define PHP_HTTP_INFO_H
15
16 #include "php_http_version.h"
17 #include "php_http_url.h"
18
19 #define PHP_HTTP_INFO_REQUEST_FMT_ARGS(_http_ptr, tmp, eol) "%s %s HTTP/%u.%u" eol, \
20 (_http_ptr)->info.request.method?(_http_ptr)->info.request.method:"UNKNOWN", \
21 (_http_ptr)->info.request.method&&!strcasecmp((_http_ptr)->info.request.method,"CONNECT")?( \
22 (_http_ptr)->info.request.url?php_http_url_authority_to_string((_http_ptr)->info.request.url, &(tmp), NULL):"0"):( \
23 (_http_ptr)->info.request.url?php_http_url_to_string((_http_ptr)->info.request.url, &(tmp), NULL, 0):"/"), \
24 (_http_ptr)->version.major||(_http_ptr)->version.major?(_http_ptr)->version.major:1, \
25 (_http_ptr)->version.major||(_http_ptr)->version.minor?(_http_ptr)->version.minor:1
26
27 #define PHP_HTTP_INFO_RESPONSE_FMT_ARGS(_http_ptr, tmp, eol) "HTTP/%u.%u %d%s%s" eol, \
28 (_http_ptr)->version.major||(_http_ptr)->version.major?(_http_ptr)->version.major:1, \
29 (_http_ptr)->version.major||(_http_ptr)->version.minor?(_http_ptr)->version.minor:1, \
30 (_http_ptr)->info.response.code?(_http_ptr)->info.response.code:200, \
31 (_http_ptr)->info.response.status&&*(_http_ptr)->info.response.status ? " ":"", \
32 STR_PTR((_http_ptr)->info.response.status)
33
34 typedef struct php_http_info_data {
35 union {
36 /* GET /foo/bar */
37 struct { char *method; php_http_url_t *url; } request;
38 /* 200 Ok */
39 struct { unsigned code; char *status; } response;
40 } info;
41 php_http_version_t version;
42 } php_http_info_data_t;
43
44 typedef enum php_http_info_type {
45 PHP_HTTP_NONE = 0,
46 PHP_HTTP_REQUEST,
47 PHP_HTTP_RESPONSE
48 } php_http_info_type_t;
49
50 #define PHP_HTTP_INFO(ptr) (ptr)->http.info
51 #define PHP_HTTP_INFO_IMPL(_http, _type) \
52 php_http_info_data_t _http; \
53 php_http_info_type_t _type;
54
55 typedef struct php_http_info {
56 PHP_HTTP_INFO_IMPL(http, type)
57 } php_http_info_t;
58
59 typedef zend_bool (*php_http_info_callback_t)(void **callback_data, HashTable **headers, php_http_info_t *info TSRMLS_DC);
60
61 PHP_HTTP_API php_http_info_t *php_http_info_init(php_http_info_t *info TSRMLS_DC);
62 PHP_HTTP_API php_http_info_t *php_http_info_parse(php_http_info_t *info, const char *pre_header TSRMLS_DC);
63 PHP_HTTP_API void php_http_info_dtor(php_http_info_t *info);
64 PHP_HTTP_API void php_http_info_free(php_http_info_t **info);
65
66 #endif
67
68 /*
69 * Local variables:
70 * tab-width: 4
71 * c-basic-offset: 4
72 * End:
73 * vim600: noet sw=4 ts=4 fdm=marker
74 * vim<600: noet sw=4 ts=4
75 */
76