2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.0 of the PHP license, that |
6 | is bundled with this package in the file LICENSE, and is available |
7 | through the world-wide-web at http://www.php.net/license/3_0.txt. |
8 | If you did not receive a copy of the PHP license and are unable to |
9 | obtain it through the world-wide-web, please send a note to |
10 | license@php.net so we can mail you a copy immediately. |
11 +----------------------------------------------------------------------+
12 | Copyright (c) 2004-2005 Michael Wallner <mike@php.net> |
13 +----------------------------------------------------------------------+
24 #include "php_http_api.h"
25 #include "php_http_std_defs.h"
26 #include "php_http_info_api.h"
30 ZEND_EXTERN_MODULE_GLOBALS(http
);
32 PHP_HTTP_API
void _http_info_default_callback(void **nothing
, HashTable
**headers
, http_info
*info TSRMLS_DC
)
35 Z_ARRVAL(array
) = *headers
;
40 add_assoc_string(&array
, "Request Method", HTTP_INFO(info
).request
.method
, 1);
41 add_assoc_string(&array
, "Request Uri", HTTP_INFO(info
).request
.URI
, 1);
44 case IS_HTTP_RESPONSE
:
45 add_assoc_long(&array
, "Response Code", (long) HTTP_INFO(info
).response
.code
);
46 add_assoc_string(&array
, "Response Status", HTTP_INFO(info
).response
.status
, 1);
51 PHP_HTTP_API
void _http_info_dtor(http_info
*info
)
53 http_info_t
*i
= (http_info_t
*) info
;
58 STR_SET(i
->request
.method
, NULL
);
59 STR_SET(i
->request
.URI
, NULL
);
62 case IS_HTTP_RESPONSE
:
63 STR_SET(i
->response
.status
, NULL
);
71 PHP_HTTP_API STATUS
_http_info_parse_ex(const char *pre_header
, http_info
*info
, zend_bool silent TSRMLS_DC
)
73 const char *end
, *http
;
76 if ((!pre_header
) || (!*pre_header
)) {
78 http_error(HE_WARNING
, HTTP_E_MALFORMED_HEADERS
, "Empty pre-header HTTP info");
83 /* where's the end of the line */
84 if (!((end
= strchr(pre_header
, '\r')) || (end
= strchr(pre_header
, '\n')))) {
85 end
= pre_header
+ strlen(pre_header
);
88 /* there must be HTTP/1.x in the line
89 * and nothing than SPACE or NUL after HTTP/1.x
91 if ( (!(http
= strstr(pre_header
, "HTTP/1."))) ||
93 (!isdigit(http
[lenof("HTTP/1.")])) ||
94 (http
[lenof("HTTP/1.1")] && (!isspace(http
[lenof("HTTP/1.1")])))) {
96 http_error(HE_WARNING
, HTTP_E_MALFORMED_HEADERS
, "Invalid or missing HTTP/1.x protocol identification");
103 char *line
= estrndup(pre_header
, end
- pre_header
);
104 fprintf(stderr
, "http_parse_info('%s')\n", line
);
109 info
->http
.version
= atof(http
+ lenof("HTTP/"));
112 if (pre_header
== http
) {
114 const char *code
= http
+ sizeof("HTTP/1.1");
116 info
->type
= IS_HTTP_RESPONSE
;
117 HTTP_INFO(info
).response
.code
= (code
&& (end
> code
)) ? strtol(code
, &status
, 10) : 0;
118 HTTP_INFO(info
).response
.status
= (status
&& (end
> ++status
)) ? estrndup(status
, end
- status
) : ecalloc(1,1);
125 const char *url
= strchr(pre_header
, ' ');
127 info
->type
= IS_HTTP_REQUEST
;
128 if (url
&& http
> url
) {
129 HTTP_INFO(info
).request
.method
= estrndup(pre_header
, url
- pre_header
);
130 HTTP_INFO(info
).request
.URI
= estrndup(url
+ 1, http
- url
- 2);
132 HTTP_INFO(info
).request
.method
= ecalloc(1,1);
133 HTTP_INFO(info
).request
.URI
= ecalloc(1,1);
146 * vim600: noet sw=4 ts=4 fdm=marker
147 * vim<600: noet sw=4 ts=4