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