fix problem when finishing a chunked encoding stream
[m6w6/ext-http] / php_http_request_info.c
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-2010, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
11 */
12
13 /* $Id: http_request_info.c 293136 2010-01-05 08:48:52Z mike $ */
14
15 #include "php_http.h"
16
17 PHP_HTTP_API void php_http_request_info(php_http_request_t *request, HashTable *info)
18 {
19 char *c;
20 long l;
21 double d;
22 struct curl_slist *s, *p;
23 zval *subarray, array;
24 INIT_PZVAL_ARRAY(&array, info);
25
26 /* BEGIN */
27 if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_EFFECTIVE_URL, &c)) {
28 add_assoc_string_ex(&array, "effective_url", sizeof("effective_url"), c ? c : "", 1);
29 }
30 if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_RESPONSE_CODE, &l)) {
31 add_assoc_long_ex(&array, "response_code", sizeof("response_code"), l);
32 }
33 if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_TOTAL_TIME, &d)) {
34 add_assoc_double_ex(&array, "total_time", sizeof("total_time"), d);
35 }
36 if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_NAMELOOKUP_TIME, &d)) {
37 add_assoc_double_ex(&array, "namelookup_time", sizeof("namelookup_time"), d);
38 }
39 if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_CONNECT_TIME, &d)) {
40 add_assoc_double_ex(&array, "connect_time", sizeof("connect_time"), d);
41 }
42 if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_PRETRANSFER_TIME, &d)) {
43 add_assoc_double_ex(&array, "pretransfer_time", sizeof("pretransfer_time"), d);
44 }
45 if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_SIZE_UPLOAD, &d)) {
46 add_assoc_double_ex(&array, "size_upload", sizeof("size_upload"), d);
47 }
48 if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_SIZE_DOWNLOAD, &d)) {
49 add_assoc_double_ex(&array, "size_download", sizeof("size_download"), d);
50 }
51 if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_SPEED_DOWNLOAD, &d)) {
52 add_assoc_double_ex(&array, "speed_download", sizeof("speed_download"), d);
53 }
54 if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_SPEED_UPLOAD, &d)) {
55 add_assoc_double_ex(&array, "speed_upload", sizeof("speed_upload"), d);
56 }
57 if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_HEADER_SIZE, &l)) {
58 add_assoc_long_ex(&array, "header_size", sizeof("header_size"), l);
59 }
60 if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_REQUEST_SIZE, &l)) {
61 add_assoc_long_ex(&array, "request_size", sizeof("request_size"), l);
62 }
63 if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_SSL_VERIFYRESULT, &l)) {
64 add_assoc_long_ex(&array, "ssl_verifyresult", sizeof("ssl_verifyresult"), l);
65 }
66 if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_FILETIME, &l)) {
67 add_assoc_long_ex(&array, "filetime", sizeof("filetime"), l);
68 }
69 if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d)) {
70 add_assoc_double_ex(&array, "content_length_download", sizeof("content_length_download"), d);
71 }
72 if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_CONTENT_LENGTH_UPLOAD, &d)) {
73 add_assoc_double_ex(&array, "content_length_upload", sizeof("content_length_upload"), d);
74 }
75 if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_STARTTRANSFER_TIME, &d)) {
76 add_assoc_double_ex(&array, "starttransfer_time", sizeof("starttransfer_time"), d);
77 }
78 if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_CONTENT_TYPE, &c)) {
79 add_assoc_string_ex(&array, "content_type", sizeof("content_type"), c ? c : "", 1);
80 }
81 if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_REDIRECT_TIME, &d)) {
82 add_assoc_double_ex(&array, "redirect_time", sizeof("redirect_time"), d);
83 }
84 if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_REDIRECT_COUNT, &l)) {
85 add_assoc_long_ex(&array, "redirect_count", sizeof("redirect_count"), l);
86 }
87 if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_HTTP_CONNECTCODE, &l)) {
88 add_assoc_long_ex(&array, "connect_code", sizeof("connect_code"), l);
89 }
90 if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_HTTPAUTH_AVAIL, &l)) {
91 add_assoc_long_ex(&array, "httpauth_avail", sizeof("httpauth_avail"), l);
92 }
93 if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_PROXYAUTH_AVAIL, &l)) {
94 add_assoc_long_ex(&array, "proxyauth_avail", sizeof("proxyauth_avail"), l);
95 }
96 if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_OS_ERRNO, &l)) {
97 add_assoc_long_ex(&array, "os_errno", sizeof("os_errno"), l);
98 }
99 if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_NUM_CONNECTS, &l)) {
100 add_assoc_long_ex(&array, "num_connects", sizeof("num_connects"), l);
101 }
102 if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_SSL_ENGINES, &s)) {
103 MAKE_STD_ZVAL(subarray);
104 array_init(subarray);
105 for (p = s; p; p = p->next) {
106 if (p->data) {
107 add_next_index_string(subarray, p->data, 1);
108 }
109 }
110 add_assoc_zval_ex(&array, "ssl_engines", sizeof("ssl_engines"), subarray);
111 curl_slist_free_all(s);
112 }
113 #if PHP_HTTP_CURL_VERSION(7,14,1)
114 if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_COOKIELIST, &s)) {
115 MAKE_STD_ZVAL(subarray);
116 array_init(subarray);
117 for (p = s; p; p = p->next) {
118 if (p->data) {
119 add_next_index_string(subarray, p->data, 1);
120 }
121 }
122 add_assoc_zval_ex(&array, "cookies", sizeof("cookies"), subarray);
123 curl_slist_free_all(s);
124 }
125 #endif
126 #if PHP_HTTP_CURL_VERSION(7,18,2)
127 if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_REDIRECT_URL, &c)) {
128 add_assoc_string_ex(&array, "redirect_url", sizeof("redirect_url"), c ? c : "", 1);
129 }
130 #endif
131 #if PHP_HTTP_CURL_VERSION(7,19,0)
132 if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_PRIMARY_IP, &c)) {
133 add_assoc_string_ex(&array, "primary_ip", sizeof("primary_ip"), c ? c : "", 1);
134 }
135 #endif
136 #if PHP_HTTP_CURL_VERSION(7,19,0)
137 if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_APPCONNECT_TIME, &d)) {
138 add_assoc_double_ex(&array, "appconnect_time", sizeof("appconnect_time"), d);
139 }
140 #endif
141 #if PHP_HTTP_CURL_VERSION(7,19,4)
142 if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_CONDITION_UNMET, &l)) {
143 add_assoc_long_ex(&array, "condition_unmet", sizeof("condition_unmet"), l);
144 }
145 #endif
146 /* END */
147 #if PHP_HTTP_CURL_VERSION(7,19,1) && defined(PHP_HTTP_HAVE_OPENSSL)
148 {
149 int i;
150 zval *ci_array;
151 struct curl_certinfo *ci;
152 char *colon, *keyname;
153
154 if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_CERTINFO, &ci)) {
155 MAKE_STD_ZVAL(ci_array);
156 array_init(ci_array);
157
158 for (i = 0; i < ci->num_of_certs; ++i) {
159 s = ci->certinfo[i];
160
161 MAKE_STD_ZVAL(subarray);
162 array_init(subarray);
163 for (p = s; p; p = p->next) {
164 if (p->data) {
165 if ((colon = strchr(p->data, ':'))) {
166 keyname = estrndup(p->data, colon - p->data);
167 add_assoc_string_ex(subarray, keyname, colon - p->data + 1, colon + 1, 1);
168 efree(keyname);
169 } else {
170 add_next_index_string(subarray, p->data, 1);
171 }
172 }
173 }
174 add_next_index_zval(ci_array, subarray);
175 }
176 add_assoc_zval_ex(&array, "certinfo", sizeof("certinfo"), ci_array);
177 }
178 }
179 #endif
180 add_assoc_string_ex(&array, "error", sizeof("error"), php_http_request_storage_get(request->ch)->errorbuffer, 1);
181 }
182
183
184 /*
185 * Local variables:
186 * tab-width: 4
187 * c-basic-offset: 4
188 * End:
189 * vim600: noet sw=4 ts=4 fdm=marker
190 * vim<600: noet sw=4 ts=4
191 */