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