prepare v4.2.5
[m6w6/ext-http] / scripts / gen_curlinfo.php
1 #!/usr/bin/env php
2 <?php
3
4 error_reporting(0);
5
6 function failure() {
7 fprintf(STDERR, "FAILURE: %s\n", error_get_last()["message"]);
8 exit(-1);
9 }
10
11 function file_re($file, $pattern, $all = true) {
12 static $path;
13
14 $path or $path = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1].'/include/curl/' : "/usr/local/include/curl/";
15
16 if ($content = file_get_contents($path . $file)) {
17 if ($all) {
18 if (preg_match_all($pattern, $content, $matches, PREG_SET_ORDER)) {
19 return $matches;
20 }
21 } else {
22 if (preg_match($pattern, $content, $matches)) {
23 return $matches;
24 }
25 }
26 trigger_error("no match in $file for $pattern");
27 }
28 failure();
29 }
30
31 $ifdefs = array(
32 'PRIMARY_IP' => 'PHP_HTTP_CURL_VERSION(7,19,0)',
33 'APPCONNECT_TIME' => 'PHP_HTTP_CURL_VERSION(7,19,0)',
34 'CONDITION_UNMET' => 'PHP_HTTP_CURL_VERSION(7,19,4)',
35 'PRIMARY_PORT' => 'PHP_HTTP_CURL_VERSION(7,21,0)',
36 'LOCAL_PORT' => 'PHP_HTTP_CURL_VERSION(7,21,0)',
37 'LOCAL_IP' => 'PHP_HTTP_CURL_VERSION(7,21,0)',
38 'HTTP_VERSION' => 'PHP_HTTP_CURL_VERSION(7,50,0)',
39 'PROXY_SSL_VERIFYRESULT' => 'PHP_HTTP_CURL_VERSION(7,52,0)',
40 'PROTOCOL' => 'PHP_HTTP_CURL_VERSION(7,52,0)',
41 'SCHEME' => 'PHP_HTTP_CURL_VERSION(7,52,0)',
42 'RETRY_AFTER' => 'PHP_HTTP_CURL_VERSION(7,66,0)',
43 'EFFECTIVE_METHOD' => 'PHP_HTTP_CURL_VERSION(7,72,0)',
44 'PROXY_ERROR' => 'PHP_HTTP_CURL_VERSION(7,73,0)',
45 'REFERER' => 'PHP_HTTP_CURL_VERSION(7,76,0)',
46 'CAINFO' => 'PHP_HTTP_CURL_VERSION(7,84,0)',
47 'CAPATH' => 'PHP_HTTP_CURL_VERSION(7,84,0)',
48 );
49 $exclude = array(
50 'ACTIVESOCKET',
51 'CERTINFO',
52 'COOKIELIST',
53 'FTP_ENTRY_PATH',
54 'LASTSOCKET',
55 'PRIVATE',
56 'RTSP_CLIENT_CSEQ',
57 'RTSP_CSEQ_RECV',
58 'RTSP_SERVER_CSEQ',
59 'RTSP_SESSION_ID',
60 'TLS_SESSION',
61 'TLS_SSL_PTR',
62 );
63
64 $translate = array(
65 'HTTP_CONNECTCODE' => "connect_code",
66 'COOKIELIST' => 'cookies',
67 );
68
69 $templates = array(
70 'STRING' =>
71 ' if (CURLE_OK == curl_easy_getinfo(ch, %s, &c)) {
72 ZVAL_STRING(&tmp, STR_PTR(c));
73 zend_hash_str_update(info, "%s", lenof("%2$s"), &tmp);
74 }
75 ',
76 'DOUBLE' =>
77 ' if (CURLE_OK == curl_easy_getinfo(ch, %s, &d)) {
78 ZVAL_DOUBLE(&tmp, d);
79 zend_hash_str_update(info, "%s", lenof("%2$s"), &tmp);
80 }
81 ',
82 'LONG' =>
83 ' if (CURLE_OK == curl_easy_getinfo(ch, %s, &l)) {
84 ZVAL_LONG(&tmp, l);
85 zend_hash_str_update(info, "%s", lenof("%2$s"), &tmp);
86 }
87 ',
88 'OFF_T' =>
89 ' if (CURLE_OK == curl_easy_getinfo(ch, %s, &o)) {
90 ZVAL_LONG(&tmp, o);
91 zend_hash_str_update(info, "%s", lenof("%2$s"), &tmp);
92 }
93 ',
94 'SLIST' =>
95 ' if (CURLE_OK == curl_easy_getinfo(ch, %s, &s)) {
96 array_init(&tmp);
97 for (p = s; p; p = p->next) {
98 if (p->data) {
99 add_next_index_string(&tmp, p->data);
100 }
101 }
102 zend_hash_str_update(info, "%s", lenof("%2$s"), &tmp);
103 curl_slist_free_all(s);
104 }
105 ',
106 );
107
108 $infos = file_re('curl.h', '/\s*(CURLINFO_(\w+))\s*(?:CURL_DEPRECATED\(\d+\.\d+\.\d+,\s*"[\w _-]+"\))?\s*=\s*CURLINFO_(STRING|LONG|DOUBLE|SLIST|OFF_T)\s*\+\s*\d+\s*,?\s*/m');
109 var_dump($infos);
110 ob_start();
111 foreach ($infos as $info) {
112 list(, $full, $short, $type) = $info;
113 if (in_array($short, $exclude)) continue;
114 if (isset($ifdefs[$short])) printf("#if %s\n", $ifdefs[$short]);
115 printf($templates[$type], $full, strtolower((isset($translate[$short])) ? $translate[$short] : $short));
116 if (isset($ifdefs[$short])) printf("#endif\n");
117 }
118
119 file_put_contents("src/php_http_client_curl.c",
120 preg_replace('/(\/\* BEGIN::CURLINFO \*\/\n).*(\n\s*\/\* END::CURLINFO \*\/)/s', '$1'. ob_get_contents() .'$2',
121 file_get_contents("src/php_http_client_curl.c")));
122
123 ?>