2 +--------------------------------------------------------------------+
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-2006, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
17 #include "php_http_api.h"
18 #include "php_http_info_api.h"
20 PHP_HTTP_API
void _http_info_default_callback(void **nothing
, HashTable
**headers
, http_info
*info TSRMLS_DC
)
24 INIT_ZARR(array
, *headers
);
29 add_assoc_string(&array
, "Request Method", HTTP_INFO(info
).request
.method
, 1);
30 add_assoc_string(&array
, "Request Url", HTTP_INFO(info
).request
.url
, 1);
33 case IS_HTTP_RESPONSE
:
34 add_assoc_long(&array
, "Response Code", (long) HTTP_INFO(info
).response
.code
);
35 add_assoc_string(&array
, "Response Status", HTTP_INFO(info
).response
.status
, 1);
40 PHP_HTTP_API
void _http_info_dtor(http_info
*i
)
45 STR_SET(HTTP_INFO(i
).request
.method
, NULL
);
46 STR_SET(HTTP_INFO(i
).request
.url
, NULL
);
49 case IS_HTTP_RESPONSE
:
50 STR_SET(HTTP_INFO(i
).response
.status
, NULL
);
58 PHP_HTTP_API STATUS
_http_info_parse_ex(const char *pre_header
, http_info
*info
, zend_bool silent TSRMLS_DC
)
60 const char *end
, *http
;
63 if ((!pre_header
) || (!*pre_header
)) {
65 http_error(HE_WARNING
, HTTP_E_MALFORMED_HEADERS
, "Empty pre-header HTTP info");
70 /* where's the end of the line */
71 if (!(end
= http_locate_eol(pre_header
, NULL
))) {
72 end
= pre_header
+ strlen(pre_header
);
75 /* there must be HTTP/1.x in the line
76 * and nothing than SPACE or NUL after HTTP/1.x
78 if ( (!(http
= php_memnstr((char *) pre_header
, "HTTP/1.", lenof("HTTP/1."), (char *)end
))) ||
80 (!isdigit(http
[lenof("HTTP/1.")])) ||
81 (http
[lenof("HTTP/1.1")] && (!isspace(http
[lenof("HTTP/1.1")])))) {
83 http_error(HE_WARNING
, HTTP_E_MALFORMED_HEADERS
, "Invalid or missing HTTP/1.x protocol identification");
90 char *line
= estrndup(pre_header
, end
- pre_header
);
91 fprintf(stderr
, "http_parse_info('%s')\n", line
);
96 info
->http
.version
= atof(http
+ lenof("HTTP/"));
99 if (pre_header
== http
) {
101 const char *code
= http
+ sizeof("HTTP/1.1");
103 info
->type
= IS_HTTP_RESPONSE
;
104 HTTP_INFO(info
).response
.code
= (code
&& (end
> code
)) ? strtol(code
, &status
, 10) : 0;
105 HTTP_INFO(info
).response
.status
= (status
&& (end
> ++status
)) ? estrndup(status
, end
- status
) : ecalloc(1,1);
111 else if (!http
[lenof("HTTP/1.x")] || http
[lenof("HTTP/1.x")] == '\r' || http
[lenof("HTTP/1.x")] == '\n') {
112 const char *url
= strchr(pre_header
, ' ');
114 info
->type
= IS_HTTP_REQUEST
;
115 if (url
&& http
> url
) {
116 HTTP_INFO(info
).request
.method
= estrndup(pre_header
, url
- pre_header
);
117 HTTP_INFO(info
).request
.url
= estrndup(url
+ 1, http
- url
- 2);
119 HTTP_INFO(info
).request
.method
= ecalloc(1,1);
120 HTTP_INFO(info
).request
.url
= ecalloc(1,1);
126 /* some darn header containing HTTP/1.x */
138 * vim600: noet sw=4 ts=4 fdm=marker
139 * vim<600: noet sw=4 ts=4